用函数来比较两个数的最大值

//
// Copyright (C) 2014软件技术1班
// All rights reserved.(版权所有)
//作者:A36 黄阿德
//完成日期:2014年12月3日
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            double one, two;
            Console.WriteLine("请输入一个数:");
            one = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入另一个数:");
            two = double.Parse(Console.ReadLine());
            Console.WriteLine("The Max value is:{0}", Max(one, two));
            Console.ReadKey();
            Max(one, two);
        }
        static double Max(double one,double two)
        {
            if (one < two) return two;
            return one;

        }
    }
}

时间: 2024-08-06 16:30:30

用函数来比较两个数的最大值的相关文章

编程题:返回指针值的函数,求两个数中较大的数。

#include<stdio.h> int *max(int *x,int *y) { int *q; if(*x>*y)  q=x; else  q=y; return q; } void main() { int a,b,*p; scanf("%d,%d",&a,&b); p=max(&a,&b); printf("%d,%d,max is %d\n",a,b,*p); } 编程题:返回指针值的函数,求两个数中较

c语言函数实现交换两个数的值

代码: 1 #include <stdio.h> 2 3 void swap(int x,int y) 4 { 5 int temp; 6 7 temp = x; 8 x = y; 9 y = temp; 10 printf("In swap: x = %d,y = %d\n",x,y); 11 } 12 13 void swap_with_pt(int * x,int * y) 14 { 15 int temp; 16 17 temp = *x; 18 *x = *y;

使用函数输出两个数的最大值

使用函数输出两个数中的最大值: 其中:第一行输入一个整数n,代表有n组测试数据: 后面输出的是两个值中较大的一个,每组测试数据占一行. 1 #include<stdio.h> 2 int max(int x,int y); 3 int main(void) 4 { 5 int a,b,c; 6 int n,i; 7 scanf("%d",&n); 8 for(i=0;i<n;i++){ 9 scanf("%d%d",&a,&

N个未排序的随机数,在线性时间内,求这N个数在数轴上相邻两个数的最大值

1 public class MaxSub 2 { 3 public static void main(String[] args) 4 { 5 int[] a ={5,7,3,1,6,2}; 6 System.out.println(maxSub(a)); 7 8 } 9 10 /** 11 * @用于找出N个随机数在数轴相邻位置的最大差值 12 */ 13 public static int maxSub(int[] a) 14 { 15 int min=a[0];//初始化数组的最小值mi

Sass函数-comparable 判断两个数是否可进行加减、合并

comparable() 函数主要是用来判断两个数是否可以进行"加,减"以及"合并".如果可以返回的值为 true,如果不可以返回的值是 false: >> comparable(2px,1px) true >> comparable(2px,1%) false >> comparable(2px,1em) false >> comparable(2rem,1em) false >> comparable(

两个数求最大值------函数的模板

#include<iostream> using namespace std; template <class T> T max(T a, T b){ return a > b ? a : b;} int main(int argc,char* argv[]){ int x = 10; int y = 20; cout << "max = " << max(10, 20) << endl; cin >> x;

C++求两个数的最大值

//不使用if,:?等判断语句,求两个数字中最大的那个数字. #include<iostream> using namespace std; int main() { int a = -10; int b = -100; int c = (a + b + abs(a - b))/2; //abs(x)是求绝对值的函数,a+b+(a与b的差值)就是最大数的两倍,再除以2即为最大数. cout << c << endl; return 0; } #include <i

Oracle函数:求两个数的最大公约数

1 CREATE OR REPLACE FUNCTION GETGYS(NUM1 NUMBER, NUM2 NUMBER) RETURN NUMBER IS 2 RESULTNUM NUMBER; 3 NUM3 NUMBER; 4 MINNUM NUMBER; 5 BEGIN 6 IF NUM1 >= NUM2 THEN 7 MINNUM := NUM2; 8 ELSE 9 MINNUM := NUM1; 10 END IF; 11 NUM3 := MINNUM; 12 LOOP 13 IF (

void swap(int a,int b)这样一个函数原型能交换两个数么?可以!!

昨天在指导别人指针的时候,突发奇想想到这么一道题,我觉得挺有意思的,发给大家看看,虽然不是什么很高级的技术,但是是个很有趣的思路..... 题目就是: void swap(int a,int b)这个函数原型,不能用全局变量与静态变量的情况下,怎么实现交换两个数? 如果你有兴趣可以思考一下,如果没兴趣就直接看下面的答案吧. --------------------------------------------------华丽的分割线-------------------------------