编写求三个数最大值的函数 用C语言

如题所述

#include <stdio.h>int maxfun(int a,int b) //直接用三目运算符? :实现.
{
return a>b?a:b;
}
void main()
{
int a,b,c,max;
scanf("%d%d%d",&a,&b,&c); //从键盘输入三个数.
max=maxfun(a,maxfun(b,c)); //调用函数. 返回三个数中的最大数.
printf("max=%d\n",max); //输出最大数
}****************************************************************************************用if语句实现:#include <stdio.h>int maxfun(int a,int b,int c) //if 结构. 函数返回三个数中的最大数.
{
int max=a;
if(max<b) max=b;
if(max<c) max=c;
return max;
}
void main()
{
int a,b,c,max;
scanf("%d%d%d",&a,&b,&c); //从键盘输入三个数.
max=maxfun(a,b,c); //调用函数. 返回三个数中的最大数.
printf("max=%d\n",max); //输出最大数.
嘿嘿......手快有..手慢就没咯...
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-21
我的楼。。。

#include <stdio.h>

int main()
{
int a,b,c,m;
printf( "请输入三个整数:" );
scanf( "%d%d%d", &a, &b, &c );
m = a;
if ( m < b ) m = b;
if ( m < c ) m = c;
printf( "其中的最大值是:%d\n\n", m );
}
第2个回答  2013-11-21
double checkMaxValue(double a, double b, double c){ double MaxValue = a; if(b>MaxValue) { MaxValue = b; } if(c>MaxValue) { MaxValue = c; } return MaxValue;}
第3个回答  2017-07-03
#includeusingnamespacestd;intmax(int,int);intmax(intm,intn){return(m>n)?m:n;}intmain(){cout>x>>y>>z;cout<<"这三个整数中最大的是:";cout<<max(max(x,y),z)<<endl;}本回答被网友采纳
第4个回答  2013-11-21
简直就是来送分的题,马甲的嫌疑啊。
相似回答