中国大学MOOC:下列求100以内所有偶数之和的程序是否正确?sum=0i=0whilei<100:ifi%2==0:sum+=ii+=2printsum
举一反三
- 在下列程序段中,不能计算1到100之间奇数之和的是__________。 A: Dim sum As Integer sum = 0 For i = 1 To 100 Step 2 sum = sum + i Next B: Dim sum As Integer sum = 0 For i = 1 To 100 If i Mod 2 <> 0 Then sum = sum + i Next C: Dim sum As Integer sum = 0 For i = 1 To 99 sum = sum + i Next D: Dim sum As Integer sum = 0 For i = 100 To 1 Step -1 If i Mod 2 <> 0 Then sum = sum + i Next
- $sum = 0; for($i=1;$i<=100;;++$i){ if($i%2==0){ continue; } $sum += $i; } echo '$sum ='.$sum; echo输出值为_______。 2、 $sum = 0; for($i=1;$i<=100;;++$i){ if($i%2==0){ continue; } $sum += $i; } echo '$sum ='.$sum; echo输出值为_______
- 1. 以下求10以内的所有奇数之和的值是() sum = 0 i= 1 while i < 10: if i % 2 !=0: sum += i i ++ print (sum)
- 下列循环做什么?sum的最终值是多少?int sum=0;for(int i=-100;i<=100;++i) sum+=i;
- i=sum=0whilei<=4:sum+=ii=i+1int(sum)代码输出的结果是: A: 0 B: 10 C: 4 D: 以上结果都不对。