首页 > 试题广场 >

当给定下述输出时,下列程序将打印出什么? q c g b #

[问答题]

当给定下述输出时,下列程序将打印出什么?
q
c
g
b

#include <stdio.h>
 int main (void)
 {
 char ch;
while ((ch = getchar())!= '#')
 {
 if (ch == '\n')
 continue;
 printf ("Step 1\n");
 if (ch == 'c')
 continue;
 else if (ch == 'b')
 break;
 else if (ch == 'g')
 goto laststep;
 printf ("Step 2\n");
 laststep: printf ("Step 3\n");
 }
 printf ("Done\n");
 return 0;
 }

推荐
这里是使用给定的输入时的运行结果:
q
Step 1
Step 2
Step 3
c
Step 1
g
Step 1
Step 3
b
Step 1
Done
注意b和#都可以结束循环,但是输入b会引起打印Step1,输入#则不会。
发表于 2018-03-25 09:19:50 回复(0)