设有如下程序:
Private Sub Command1_Click()
Dim sum As Double, x As Double
sum=0
n=0
For i=1 To 5
x=n/i
n=n+1
sum=sum+x
Next i
End Sub
该程序通过For循环来计算一个表达式的值,这个表达式是
Private Sub Command1_Click()
Dim sum As Double, x As Double
sum=0
n=0
For i=1 To 5
x=n/i
n=n+1
sum=sum+x
Next i
End Sub
该程序通过For循环来计算一个表达式的值,这个表达式是
举一反三
- 声明一个变量为局部变量应该用( )。 A: Private Sub Command1 Click() n=5:x=1 Do X=X * I I=I + 1 Loop While I < n Print x End Sub B: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X*I I=I + 1 Loop While I <n Print x End Sub C: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X * I I=I + 1 Loop While I<=n Print X End Sub D: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X * I I=I + 1 Loop While I>n Print X End Sub
- 有如下事件过程 Private Sub Command1_Click() S=P(1)+P(2)+P(3)+P(4) Print S End Sub Public Function P(n As Integer) Static sum For i=1 To n sum=sum+i Next I P=sum End Function 单击命令按钮后,程序执行的结果是
- 运行下面的程序,第二行显示结果是___________。 Private Sub Form_Click() Dim A As Integer Dim i As Integer A = 5 For i = 1 To 9 Call sub1(i, A) Print i, A Next i End Sub Private Sub sub1(x As Integer, y As Integer) Static N As Integer Dim I As Integer For I = 3 To 1 Step -1 N = N + x x = x + 2 Next I y = y + N End Sub
- 输入一个正整数给变量n,求1到n的所有正整数之和。不正确的程序是()。 A: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1,sum=0;i<=n;i++)sum=sum+i;printf("%d",sum);} B: #includevoidmain(){inti,n,sum=0;scanf("%d",&n);for(i=1;i<=n;i++)sum=sum+i;printf("%d",sum);} C: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1;i<=n;i++)sum=sum+i;printf("%d",sum);} D: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1,sum=0;i<=n;)sum=sum+i,i++;printf("%d",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