关于C语言的if else

来源:百度知道 编辑:UC知道 时间:2024/05/22 00:15:36
#include <stdio.h>
main() {
int num1, num2, num3;
printf("Enter 3 integers :");
scanf("%d%d%d",&num1,&num2,&num3);
printf("Value of num1 : %d\n",num1);
printf("Value of num2 : %d\n",num1);
printf("Value of num3 : %d\n",num1);
if (num1 == num2)
if (num1 == num3)
printf("All are the same\n");
if (num1 > num2)
if (num1 > num3)
printf("The max is %d\n",num1);
else
printf("The max is %d\n",num3);
else if (num2 > num3)
printf("The max is %d\n",num2);
else if (num3 > num2)
printf("The max is %d\n",num3);
}
这里面的
else if (num2 > num3)
printf("The max is %d\n",num2);
else if (num3 > num2)
printf("The max is %d\n",num3);
的else

首先找到一组相邻的IF Else(if在else前面出现)

if (num1 > num3)
printf("The max is %d\n",num1);
else
printf("The max is %d\n",num3);
这个else一定是上面的if的

然后假设把这一段文字删除
在删除后的文字中同样寻找相邻的

又是一组
一步步找就可以了

这段代码可读性太差了,至少要在if后加个{}吧,那样看的比较清楚
if (num1 > num3)
printf("The max is %d\n",num1);
else
这两个是一对
if (num1 > num2)
else if (num2 > num3)这2个是一对,

if (num1 == num3)
else if (num3 > num2) 这2个是一对

和他上面最进的if