我是c语言初学者,有些问题不懂.#includemain(){\x05int a,b;\x05\x05scanf("%d,%d",&a,&b);\x05\x05if(a>b) printf("%d is bigger than %d\n",a,b);\x05\x05if(a==b) printf("%d is equal to %d\n",a,b);\x05\x05else printf("%d is bigger than %d\n",b,a
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/05 19:29:32
![我是c语言初学者,有些问题不懂.#includemain(){\x05int a,b;\x05\x05scanf(](/uploads/image/z/6878155-67-5.jpg?t=%E6%88%91%E6%98%AFc%E8%AF%AD%E8%A8%80%E5%88%9D%E5%AD%A6%E8%80%85%2C%E6%9C%89%E4%BA%9B%E9%97%AE%E9%A2%98%E4%B8%8D%E6%87%82.%23includemain%28%29%7B%5Cx05int+a%2Cb%3B%5Cx05%5Cx05scanf%28%22%25d%2C%25d%22%2C%26a%2C%26b%29%3B%5Cx05%5Cx05if%28a%3Eb%29+printf%28%22%25d+is+bigger+than+%25d%5Cn%22%2Ca%2Cb%29%3B%5Cx05%5Cx05if%28a%3D%3Db%29+printf%28%22%25d+is+equal+to+%25d%5Cn%22%2Ca%2Cb%29%3B%5Cx05%5Cx05else+printf%28%22%25d+is+bigger+than+%25d%5Cn%22%2Cb%2Ca)
我是c语言初学者,有些问题不懂.#includemain(){\x05int a,b;\x05\x05scanf("%d,%d",&a,&b);\x05\x05if(a>b) printf("%d is bigger than %d\n",a,b);\x05\x05if(a==b) printf("%d is equal to %d\n",a,b);\x05\x05else printf("%d is bigger than %d\n",b,a
我是c语言初学者,有些问题不懂.
#include
main()
{
\x05int a,b;
\x05\x05scanf("%d,%d",&a,&b);
\x05\x05if(a>b) printf("%d is bigger than %d\n",a,b);
\x05\x05if(a==b) printf("%d is equal to %d\n",a,b);
\x05\x05else printf("%d is bigger than %d\n",b,a);
}
这是我编的比较大小的程序,运行的时候,输入10,5会出现
10 is bigger than 5
5 is bigger than 10
为什么会出现两个?后面的还是错的!
我是不是哪里编错了?
我是c语言初学者,有些问题不懂.#includemain(){\x05int a,b;\x05\x05scanf("%d,%d",&a,&b);\x05\x05if(a>b) printf("%d is bigger than %d\n",a,b);\x05\x05if(a==b) printf("%d is equal to %d\n",a,b);\x05\x05else printf("%d is bigger than %d\n",b,a
同意mars_room_10的回答.
程序是从上往下运行的,你的两个if是并列关系.
输入5和10之后,满足第一个if(a>b),所以会出现“10 is bigger than 5”
判断完之后它就会进入第二个if,很明显a==b是不成立的,所以就会执行else里的代码,出现“5 is bigger than 10”.
在第二个if 前面加个 else,把两个if变成嵌套关系,只有当不满足a>b的时候,才会去判断a==b满不满足.