c语言三个数求最小值,C语言 三个数求最大值的不同解法

方法一:

#include

int compare(int a,int b, int c);

int main()

{

int one,two,three,Max;

printf("please input three number you want to compare:\n");

scanf("%d%d%d",&one,&two,&three);

Max=compare(one,two,three);

printf("the Max of the [%d %d %d] is %d.\n",one,two,three,Max);

return 0;

}

int compare(int a,int b, int c)

{

if(a>b)

if(a>c)

return a;

else

return c;

else

if(b

return c;

else

return b;

}

方法二:

#include

int compare(int a,int b, int c);

int main()

{

int a,b,c,Max;

printf("please input three number you want to compare:\n");

scanf("%d%d%d",& a,& b,& c);

Max=((a>b)?((a>c)?a:c):((b

printf("the Max of the [%d %d %d] is %d.\n",a,b,c,Max);

return 0;

}

两种方法个人更倾向于第一个。