有人可以解释为什么此代码打印5 A AAAAA
而不是4 A AAAA
char 'A' - 65
,'B' - 66
和'Z' - 90
#include <stdio.h>
int main() {
char a = 'B', b = 'A';
while (a++ < 'Z') {
if (a % 5 == 0)
printf("%c", b);
}
return 0;
}
我计算了多次,结果我得到了4个A,所以我不明白为什么正确答案是5 A
答案 0 :(得分:2)
让我们“手动”遍历您的代码。
Stop condition: a < 90 ('Z')
a = 'B' = 66
...
a = 70 => 'A' printed
...
a = 75 => 'A' printed
...
a = 80 => 'A' printed
...
a = 85 => 'A' printed
...
a = 89 =>