vb编写程序计算s=1平方+2平方+3平方+…+100平方

求如题程序代码。高分
2024-11-16 01:53:58
推荐回答(5个)
回答(1):

在VB用定义不能用dim i,s,k as integer ,而要分别定义
一连串的定义方法是C里面用的
dim i as integer ,s as integer ,k as integer
k=100
for i to k
s=s+(i*i)
next

msgbox s

回答(2):

dim i,s,k as integer
k=100
for i to k
s=s+(i*i)
next

textbox1.text =s

回答(3):

在窗口建立一个commond 和 text块

Private Sub Command1_Click()
Dim i As Integer, S As Double
Dim a As Integer
a = Val(Text1.Text)
S = 0
For i = 1 To a

S = S + i ^ 2
Next i
Print S
End Sub

回答(4):

在窗口建立一个commond 和 text块

Private Sub Command1_Click()
Dim i As Integer
dim S As Long
Dim a As Integer
Text1.Text="100"
a = Val(Text1.Text)
S = 0
For i = 1 To a

S = S + i ^ 2
Next i
Text1.Text= S
End Sub

回答(5):

Dim i as Integer , S as Double
For i =1 To 100
S= S + i ^ 2
Next i
Print S