$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到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=()。 [?php $sum=0; for ($i=1;$i<=10;$i++){ if($i]5)break; $sum=$sum+$i; } echo"sum=".$sum;
- 请阅读下面的程序,sum的值为()publicclassTest{publicstaticvoidmain(String[]args){intsum=0;for(inti=1;i=100;i++){if(i%2==1){continue;}sum+=i;}System.out.println(sum=+sum);}}
- 下列哪种循环语句可以求6,8,10,12,…,66数列的和,结果存放在sum变量中 A: i=6 sum=0 while i<67: if i%2==0: sum=sum+i i=i+1 B: i=6 sum=1 while i<67: if i%2==0: sum=sum+i i=i+1 C: i=6 sum=0 while i<=66: sum=sum+i i=i+2 D: i=6 sum=0 while i<=66: sum=sum+i i=i+2
- 1. 以下求10以内的所有奇数之和的值是() sum = 0 i= 1 while i < 10: if i % 2 !=0: sum += i i ++ print (sum)