#求1-100中所有整数的和 sum=0 foriinrange(1,____): sum=sum+_____ print("sum=",sum)
举一反三
- def func(): global sum sum=0 print(sum) for i in range(5): sum+=1 print(sum) func() print(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
- 已定义i和sum都为整数,以下C语言程序段的功能为( )。sum=0; i=1;while(i<=100){ sum=sum+i; i++;}printf(“%d”,sum); A: 求1到100内所有整数的积 B: 求1到100内所有偶数的和 C: 求1到100内所有整数的和 D: 求1到100内所有奇数的和
- sum=0; for i=1:2:100 sum=sum+i; end sum输出的结果是: A: 1-100内自然数的和 B: 1-100内偶数的和 C: 1-100内奇数的和 D: 100
- $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输出值为_______