和下面代码执行结束后,sum结果一致的选项是( )int i=1;int sum=0;while(i<=100){ if(i%2==0) { sum=sum+i;} i++;}
A: for (int x =1; x<=100;x++){ sum=sum+x;}
B: for (int x =0; x<=100;x+=2){ sum=sum+x;}
C: for (int x =1; x<=100;x+=2){ sum=sum+x;}
D: 上述全对
A: for (int x =1; x<=100;x++){ sum=sum+x;}
B: for (int x =0; x<=100;x+=2){ sum=sum+x;}
C: for (int x =1; x<=100;x+=2){ sum=sum+x;}
D: 上述全对
举一反三
- 以下四个选项中和下面代码功能相同的是( )。(选择一项) int i = 1; int sum = 0; while (i <= 100) { if (i % 2 == 0) sum = sum + i; i++; } A: for (int x =1; x<=100;x++){ sum=sum+x;} B: for (int x =0; x<=100;x+=2){ sum=sum+x;} C: for (int x =1; x<=100;x+=2){ sum=sum+x;} D: 上述全对
- 以下程序:void sum(int x){int i,sum=0;for (i=0;i<;5;i++){sum=sum+i;}x=sum;}main(){int x=90;sum(x);printf(“%d”,x);}执行后输出结果是_______。 A: 0 B: 10 C: 90 D: 100
- 以下四个选项中和下面代码功能相同的是。 int i = 1; int sum = 0; while (i <= 100) { if (i % 2 == 0) sum = sum + i; i++; }
- 看程序,写结果 main() { int i,sum=0; i = 1; while (i < 100) { sum = sum + i; i++; } printf("%d",sum); }
- 智慧职教: 看程序,写结果main() { int i,sum=0; i = 1; do { sum = sum +2; i++; } while (i<100); printf("%d",sum); }