有以下程序 #include <stdio.h> void main() { int a[]={2,3,5,4},i; for(i=0;i<4;i++) switch(i%2) { case 0:switch(a[i]%2)

admin2019-07-14  15

问题 有以下程序
#include <stdio.h>
void main()
{
  int a[]={2,3,5,4},i;
  for(i=0;i<4;i++)
  switch(i%2)
  {
    case 0:switch(a%2)
    {
      case 0:a++;break;
      case 1:a--;
    }break;
    case 1:a=0;
  }
  for(i=0;i<4;i++)
  printf("%d",a);
  printf("\n");
}
程序运行后的输出结果是

选项 A、2 0 5 0
B、3 3 4 4
C、3 0 4 0
D、0 3 0 4

答案C

解析 在主函数的for循环语句中,当循环变量i的值等于0,2时,执行switch中的case 0语句,分别对数组元素a[0]和a[2]加1和减1,所以a[0]的值等于3,a[2]等于4。当循环变量i的值等于1,3时,执行switch中的case 1语句,把数组元素a[1]和a[3]的值赋为0。所以输出数组a的元素,其结果为3040。
转载请注明原文地址:https://kaotiyun.com/show/L8Rp777K
0

随机试题
最新回复(0)