这段C程序那里错了。求三个整数最大值

来源:百度知道 编辑:UC知道 时间:2024/05/10 05:42:20
#include <stdio.h>

void main()
{
int a,b,c;
printf("plerse input three number:");
scanf("%d, %d, %d", &a, &b, &c);
if((a > b)&&(a > c));
printf("the max number:%d", a);

if((b > a)&&(b > c));
printf("the max number:%d", b);

if((c > a)&&(c > b));
printf("the max number:%d", c);
}

我知道可以用条件运算求出。但不知道这个错在哪里。请各位指教

#include <stdio.h>

void main()
{
int a,b,c;
printf("plerse input three number:\n"); //一般习惯加个换行
scanf("%d, %d, %d", &a, &b, &c);
if(a>b&&a>c) //>优先级比&&高,所以不需要括号,但能看出你作为初学者很小心啊,不错。
printf("the max number:%d", a);

if(b>a&&b>c) //if条件后面不应该有;(分号)是对的
printf("the max number:%d", b);

if(c>a&&c>b)
printf("the max number:%d", c);
}

if条件后面不应该有;(分号)

像if,for这样的语句是不用加分号的,把分号去了,应该就没有什么错误了

不应该加分号,if语句它的标准形式为 if(表达式)语句;
他括号后面的语句是基于括号内的条件为真时运行的,所以你加了分号以后他就判断完了之后没有执行任何操作,和你的愿意是不符合的,只要去了分号就OK 了