急求一个简单的C语言程序

急求一个简单的C语言程序
#include
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("\nmax = %d, min = %d", (a>b)?(a>c?a:c):(b>c?b:c),(a return 0;
}
最简单的思想,假如a b c 如果a比其它两都大,那它就是最大的。采用这样的办法判断其它的数。
#include
int main(void){
double a,b,c;
printf("请输入三个数:");
scanf("%lf%lf%lf",&a,&b,&c);
/*找最大数*/
if(a>b&&a>c)(printf("max=%.2lf\n",a));
else if(b>a&&b>c)(printf("max=%.2lf\n",b));
else printf("max=%.2lf\n",c);
/*找最小数*/
if(a else if(b else printf("min=%.2lf\n",c);
return 0;
}

1楼的算法是最精炼的。
#include "iostream.h"
int getMaxorMin(int,int,bool);
int main()
{
int a,b,c;
cout << "请输入三个整数:";
cin >> a >> b >> c;
int temp = getMaxorMin(a,b,true); // 记录临时较大值
int max = getMaxorMin(temp,c,true); // 返回最终最大值
temp = getMaxorMin(a,b,false); //记录临时较小值
int min = getMaxorMin(temp,c,false); // 返回最终最小值
cout <<"最大值为:" << max << "\n最小值为:" << min << endl;
return 0;
}
int getMaxorMin(int a,int b,bool c)
{
if(c) //c为真是返回两数中的较大数,c为假时返回两数中的较小数。
return a>b ? a:b;
else
return a}
好像现在初学的都很牛B啊.
都以这个为名,上来就要代码,书上这种例子多的是,初学可以看书啊.还有讲解.
← 上一篇: 下一篇: →