高手帮看下:输入6个数,输出最小数。。。

来源:百度知道 编辑:UC知道 时间:2024/05/11 00:11:54
#include<stdio.h>
main()
{
int a, b, c, d, e, f, g;
printf("please input six numbers(a, b, c, d, e, f):");
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
if(a > b)
{
g = a;
}
else
{
g = b;
}
if(c > g)
{
g = c;
}
if(d > g)
{
g = d;
}
if(e > g)
{
g = e;
}
if(f > g)
{
g = f;
}
printf("%d, %d, %d, %d. %d. %d, the max is %d\n", a, b, c, d, e, f);
}
哪里不对了,应该怎么修改,或者还有什么方法。谢谢
哦,我看错题目了。就算是取最大数的话,我的也运行不出来正确结果:(
添上g就对了。呵呵,你们太厉害了。。。

printf("%d, %d, %d, %d. %d. %d, the max is %d\n", a, b, c, d, e, f);
g哪去了?

楼主搞错了吧,是取最大数

楼主你比法有点累看不容易找错,换个方法吧:
#include "stdio.h"
void main()
{
int a[6],i,max=-32767;
for(i=0;i<6;i++)
{
scanf("%d",&a[i]);
if(a[i]>max) max=a[i];
}
printf("%d, %d, %d, %d. %d. %d, the max is %d\n",a[0],a[1],a[2],a[3],a[4],a[5],max);
}

。。。