以下能够正确计算1+2+3+…+10的程序是
A.Private Sub Command1_Click() Sum=0 ForI=1 To 10 Sum=Sum+I Next I Print Sum End Sub
B.Private Sub Command1_Click() Sum=0,I=1 Do While I<=10 Sum=Sum+I I=I+1 Print Sum End Sub
C.Private Sub Command1_Click() Sum=0: I=1 Do Sum=Sum+I I=I+1 Loop While I<10 Print Sum End Sub
D.Private Sub Command1_Click() Sum=0: I=1 Do Sum=Sum+I I=I+1 Loop Until I<10 Print Sum End Sub
第1题:
已知程序段:
sum=0
For i=1 to 10 step 3
sum=sum+i
i=i*2
Next i
当循环结束后,变量i、sum的值分别为( )。
A.10、6
B.13、6
C.13、5
D.10、5
第2题:
执行以下程序段,程序输出结果是()。 int i=5, sum1=0; sum2=0; while(i<=4) { sum1=sum1+i; i++; } do { sum2=sum2+i; i++; }while(i<=4); printf("sum1=%d, sum2=%dn",sum1, sum2);
A.sum1=0, sum2=5
B.sum1=0, sum2=0
C.sum1=10, sum2=10
D.sum1=4, sum2=0
第3题:
在下列程序段中,不能计算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
第4题:
若有以下程序段,sum和i都是整型变量,则不能与下面程序段等价的选项是() sum=0; i=2; while(i<=10) { sum=sum+i; i++; }
A.for(i=2, sum=0; i<=10; i++) sum+=i;
B.sum=0; i=2; do{ sum=sum+i; i++; }while(i<=10);
C.sum=0; i=10; while(i>1) { sum=sum+i; i--; }
D.sum=0; i=11; do{ sum=sum+i; i--; }while(i>1);
第5题:
下面程序可以正确求出1+2+3+。。。+n的和。() #include <stdio.h> int main() { int i = 1,sum = 0,n; scanf(“%d”,&n); while (i <= n) sum = sum + i; ++i; printf("sum=%d",sum); return 0; }