//////////////////////////////////////////////////////
//求三个数的最大值和最小值
/////////////////////////////////////////////////////
#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");
}
}
相关文章
- C语言 请用程序实现: 从键盘输入一个正整数,求该正整数以内偶数的和并输出:2+4+6...+n。
- 实例15 输出三个数中的最大值和最小值
- C#中输入三个数,输出最大值和最小值——非科班小白
- 输入三个数值,输出其中的最大值和最小值
- 读入n个整数,调用max_min函数求这n个数中的最大值和最小值。
- python使用不定长参数求输入值的和、平均值、最大值和最小值
- 洛谷题单3-P5724 【深基4.习5】求极差 最大跨度值 最大值和最小值的差-python-流程图重构-题目描述
- 用 C语言实现去掉最大值最小值,再求平均值的算法
- pandas求每列的最大值和最小值
- java--案例:[Random]随机100-200的数、班级点名器、控制台输入三个数,输出最大值,或最小值?