中国大学MOOC: 以下程序段运行时,若输入1 2 3 4 5 0<回车>,输出结果是( )?ints;scanf("%d",&s);while(s>0){switch(s){case1:printf("%d",s+5);case2:printf("%d",s+4);break;case3:printf("%d",s+3);default:printf("%d",s+1);break;}scanf("%d",&s);}
举一反三
- 有以下程序,运行时若输入 123450 <回车>,则输出结果是( ) #include void main() { int s; scanf("%d",&s); while(s>0) { switch(s) { case 1:printf("%d",s+5); case2:printf("%d",s+4);break; case3:printf("%d",s+3); default:printf("%d",s+1);break; } scanf("%d",&s); } }
- 以下程序运行后的输出结果是______。 void main() { int s=0,k; for(k=7; k>=0; k--) { switch(k) { case 1: case 4: case 7: s++; break; case 2: case 3: case 6: break; case 0: case 5: s+=2; break; } } printf("s=%d\n",s); }
- 中国大学MOOC: 以下程序输出的结果是()# include <stdio.h>int main(){ int a = 4; switch(a ) { case 0: printf("this is 0\n"); break; case 1: printf("this is 1\n"); break; case 2: printf("this is 2\n"); break; default: printf("this is default\n"); } return 0;
- 3.11下面()语句与下列if语句等价。if(a>;b) s=a+b;elses=a-b; A: switch(a>;b) { case 1:s=a+b;break; case 0:s=a-b;break; } B: switch(a>;b) { case 1:s=a+b; case 0:s=a-b; } C: switch(a<;b) { case 1:s=a-b; case 0:s=a+b; } D: switch(a<;b) { case 1:s=a-b;break; case 0:s=a+b;break; }
- 下列程序段可以正确运行的有: A: int i,s,x;s=0;i=0;while(1){ scanf("%d",&x); if(x!=-1) { s=s+x; i++; } else break;}printf("ave=%d\n",s/i); B: int i,s,x;s=0;i=0;scanf("%d",&x);while(x!=-1){ s=s+x; i++; scanf("%d",&x);}printf("ave=%d\n",s/i); C: int i,s,x;s=0;i=0;while(1){ scanf("%d",&x); if(x==-1) break; s=s+x; i++; }printf("ave=%d\n",s/i);