求三个数的最大值和最小值(C程序)
2012-08-08 18:29
239 查看
//////////////////////////////////////////////////////
//求三个数的最大值和最小值
/////////////////////////////////////////////////////
#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");
}
}
//求三个数的最大值和最小值
/////////////////////////////////////////////////////
#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");
}
}
相关文章推荐
- Problem A: 编写函数:三个数的最大最小值 (Append Code)
- 一个养狗场有4只狗,体重分别为 花花:4.5kg;白白:5.6kg;黑黑:78kg;红红:9.0kg;请编写一个程序,可以计算他们的平均体重,可以找出体重最大和体重最小的狗的名字.
- 实验9(1)程序填空:下列程序在数组中同时查找最大元素和最小元素的下标,分别存放在 main()函数的max 和 min 变量中。要求:根据运行结果分析程序和填空,并注释说明填充依据。
- 编写Java程序,输入3个整数,并求出3个整数的最大值和最小值。
- 编这样一个程序,用户输入10个整数,程序找出其中的最大值和最小值
- 一个求矩阵鞍点(即行上最小的数 同时是列上最大的数)的C程序
- 对弈程序基本技术---最小-最大搜索
- c语言用指针实现求最大数和最小数的程序
- 爪哇小程序--求产生的随机数的最大值、最小值、平均数(冒泡排序法)
- 实现输入的四个数字找出最大最小并指出位置信息 动手修改程序3
- c#等程序中的关于时间的最大值【DateTime.MaxValue】和最小值【DateTime.MinValue】
- 1.编写程序,从键盘输入三个值,并打印其和、平均数、积、最小值和最大值
- MATLAB - 练习程序,求灰度图像均值、最大、最小数值
- 利用条件表达式求三个数的最大值和最小值
- oj1963: C/C++经典程序训练1---最大公约数与最小公倍数
- 算法导论程序18-最大值和最小值(Python)
- MFC 程序限制窗口最小、最大大小
- C语言:编这样一个程序,用户输入10个整数,程序找出其中的最大值和最小值
- C#取三个数的最大值、最小值、平均值、中间值
- Problem A: 编写函数:三个数的最大最小值 (Append Code)