问题源代码及答案
问题源代码及答案
程序功能:求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%