我正在尝试执行一个程序,该程序在 && 运算符返回 true 和返回 false 时打印数值。代码如下:-
#include <stdio.h>
main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("Part I\n");
printf("(a%2 == 0) && (b%2 == 0): %d\n",(a%2 == 0) && (b%2 == 0));
printf("(a%3 == 0) && (b%3 == 0): %d\n",(a%3 == 0) && (b%3 == 0));
printf("(a%5 == 0) && (b%5 == 0): %d\n",(a%5 == 0) && (b%5 == 0));
printf("(a%7 == 0) && (b%7 == 0): %d\n",(a%7 == 0) && (b%7 == 0));
printf("Part II\n");
printf("The AND operator yields: %d\n",(a%2 == 0) && (b%2 == 0));
printf("The AND operator yields: %d\n",(a%3 == 0) && (b%3 == 0));
printf("The AND operator yields: %d\n",(a%5 == 0) && (b%5 == 0));
printf("The AND operator yields: %d\n",(a%7 == 0) && (b%7 == 0));
return 0;
}
输出(连同我的输入)如下: -
210
210
Part I
(a%2 == 0) && (b%2 == 0): %d
(a%2 == 0) && (b%2 == 0): %d
(a%2 == 0) && (b%2 == 0): %d
(a%2 == 0) && (b%2 == 0): %d
Part II
The AND operator yields: 1
The AND operator yields: 1
The AND operator yields: 1
The AND operator yields: 1
为什么第一部分以这种方式表现?即使我将 && 替换为 || 也会发生这种情况。我正在使用 Borland C++ 编译器 5.5 。请帮忙。