問題源代碼及答案
問題源代碼及答案
程序功能:求s=1+3+5+7+...直到s>2000為止。程序中有兩行有錯誤。改正錯誤,使它能輸出正確的結果。
Private Sub Command1_Click()
Dim i As Integer, s As Long
s = 0
i = 1
Do Until s < 2000?????? ‘s>2000
?? s = s + i
?? i = i + 1??????????? ‘I=I+2
Loop
Print? s
End Sub
?
答案:2025
程序功能:根據整型參數m的值,計算公式t=1-1/(2*2)-1/(3*3)-…-1/(m*m)的值(m=100)。程序的函數fun()中有一行有錯誤。改正錯誤,使它能輸出正確的結果。
?
Private Sub Command1_Click()
? Print Format(fun(100), "0.######")
End Sub
?
Private Function fun(n As Integer) As Integer? ‘ Single
? Dim t As Single
? Dim i As Integer
? i = 2: t = 1
? Do While i < =n
???? t = t - 1 / (i * i)
???? i = i + 1
? Loop
? fun = t
End Function
?
?
?
答案:0.365016
程序功能:已知24有8個正整數因子(即:1,2,3,4,6,8,12,24),而24正好被其因子個數8整除。求[100,300]之間能被其因子數目整除的數中最大的數。程序中有兩行有錯誤。改正錯誤,使它能輸出正確的結果。
Private Sub Command1_Click()
Dim N As Integer
Dim s As Integer
Dim i As Integer
For N = 300 To 100?? ‘step -1
s = 0
For i = 1 To N
If N Mod i = 0 Then
s = s + 1
End If
Next i
If s Mod N = 0 Then??? ‘N Mod s=0
Print N
Exit For
End If
Next N
End Sub
答案:296
非常好我支持^.^
(6) 100%
不好我反對
(0) 0%