选择题

有以下程序:
int i,n;
for(i=0; i<8; i++)
{
    n=rand()%5;
    switch(n)
    {
         case 1:
         case 3:printf("%d\n",n);break;
         case 2:
         case 4:printf("%d\n",n);continue;
         case 0:exit(0);
    }
    printf("%d\n",n);
}
以下关于程序执行情况的叙述中, 正确的是(     )。

【正确答案】 D
【答案解析】

当产生随机数为 1 或 3 时, 会顺序执行 case1 或 case2 下面的语句, 进而输出结果; 当产生随机数为 2 或 4 时, 会继续执行循环; 当产生随机数为 0 时, 正常结束程序的运行。 for 循环语句随着产生的随机数的不同, 执行的次数也不相同。 答案选择 D 选项。