//////////////////////////////////////////////////////
//求三个数的最大值和最小值
/////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
float compTwo(float x, float y, int flag);
main()
{
float a,b,c;
float minNum,maxNum;
printf("Please input three float/int numbers:\n");
scanf("%f %f %f",&a,&b,&c);
printf("The three numbers you input are: %f %f %f\n",a,b,c);
minNum=compTwo(compTwo(a,b,0),c,0);
maxNum=compTwo(compTwo(a,b,1),c,1);
printf("The minmun number you input is: %f\n",minNum);
printf("The maxmum number you input is: %f\n",maxNum);
system("pause");
}
float compTwo(float x, float y, int flag)
{
if(flag==0)
{
return x<y?x:y; //return the small number
}
else if(flag==1)
{
return x<y?y:x; //return the large number
}
else
{
printf("Error: \"flag\" in compTwo() has a problem!\n");
}
}