求三个数中最大数的最小数的差值会C语言的帮助我弄一下!谢谢了!_百度...
发布网友
发布时间:2024-10-16 11:15
我来回答
共3个回答
热心网友
时间:2024-10-23 05:40
main()
{float a,b,c,max,min;
scanf("%f %f %f",&a,&b,&c);
max=a>b?a:b; //该表达式问a是否大于b,是的max=a,不是的max=b)
max=max>c?max:c; //原理同上,用a,b中较大的值再和c比较,求出三者之最
min=a<b?a:b
min=min<c?min:c;
printf("Answer=%f",max-min);
}
热心网友
时间:2024-10-23 05:43
#include<stdio.h>
int main() {
int firnum,secnum,tirnum;
int maxnum,minnum;
int cha;
printf("请输入三个数");
scanf("%d%d%d",&firnum,&secnum,&tirnum);
maxnum=minnum=firnum;
maxnum=firnum
if(firnum>secnum) {
maxnum=firnum;
minnum=secnum;
}else{
minxnum=firnum;
maxnum=secnum;
}
minnum=(minnum>tirnum)?tirnum:minnum;
maxnum=(maxnum>tirnum)?maxnum:tirnum;
cha=maxnum-minnum;
printf("\n最大数%d\n最小数%d\n差为%d",maxnum,minnum,cha);
return 0;
}
代码简洁很多,可能你不明白,以后会明白的
热心网友
时间:2024-10-23 05:39
#include<stdio.h>
int main()
{
int firnum,secnum,tirnum;
int maxnum,minnum;
int he,cha;
printf("请输入三个数");
scanf("%d",&firnum);
scanf("%d",&secnum);
scanf("%d",&tirnum);
maxnum=minnum=firnum;
if(secnum>firnum)
{
maxnum=secnum;
if(secnum>tirnum)
{
if(tirnum<firnum)
minnum=tirnum;
else
minnum=firnum;
}
else
maxnum=tirnum;
}
else
{
maxnum=firnum;
if(secnum<tirnum)
{
if(tirnum>firnum)
maxnum=tirnum;
}
else
minnum=tirnum;
}
he=maxnum+minnum;
cha=maxnum-minnum;
printf("最大数与最小数之和为%d。最大数与最小数之差为%d",he,cha);
return 0;
}
怎么两个人问同样问题!!
找码中判断最大值与最小值的代码不好理解,要在纸上认真画下就明白了。
祝你好运!