用VB语言求满足 1^2+2^2+3^2+4^2+…+N^2<1000最大的N值,写出代码

2025-01-02 15:36:21
推荐回答(4个)
回答1:

Dim i As Integer
Dim s As Integer
i = 1
Do
s = s + i * i
i = i + 1
Loop Until s > 1000
MsgBox i - 1
答案是14 望采纳

回答2:

sum=0
i=0
while sum <1000
i=i+1
sum=sum+i*i
wend
msgbox "最大N值为 " & i-1

回答3:

sum=0
i=0
while sum <1000
i=i+1
sum=sum+i*i
wend
msgbox "最大N值为 " & i

回答4:

Private Sub Form_Click()
s = 0
i = 1
Do While s < 1000
s = i * 2 + s
i = i + 1
Loop
Print i - 2
End Sub