求sum=1+2+3+……;当sum的值刚刚超过1000时退出循环,输出此时sum的值(答案用小写字母)Dim sum As Double, I As Integer i= 1sum = 0Do While ________sum = sum +i______________LoopPrint sum
举一反三
- 在下列程序段中,不能计算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输出值为_______
- 执行循环后,两变量 I, Sum 分别是: Dim I As Short = 1 Dim Sum As Long = 0 Do While I <= 5 Sum += I I = I + 2 Loop
- 用循环结构编写计算sum=2+4+6+……+1000的程序。main( ){inti,sum;sum=0; ————;while(————){——————;i = i + 2;}printf(“sum=%d",sum);}
- 4.编程计算1+3+5…+99的值main(){ int i, sum = 0;i=1;while ( ) { sum = sum + i; ; } printf("sum=%d\n", sum);}