使用VB编程计算S=1+2+3.......+n(n 的值由于用户定)写程序
答案:5 悬赏:80 手机版
解决时间 2021-02-07 04:25
- 提问者网友:欲劫无渡
- 2021-02-06 21:37
使用VB编程计算S=1+2+3.......+n(n 的值由于用户定)写程序
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-02-06 22:44
Dim n As Integer
Dim i As Long
Dim sSum As Long
n=vol(InputBox())
For i = 1 To n
sSum = sSum + i
Next
MsgBox sSum
Dim i As Long
Dim sSum As Long
n=vol(InputBox())
For i = 1 To n
sSum = sSum + i
Next
MsgBox sSum
全部回答
- 1楼网友:低音帝王
- 2021-02-07 02:12
private sub command1_click()
dim i as integer, j as integer, n as integer
dim sum1 as long, sum2 as long
n=inputbox("请输入n的值")
sum1 = 0
sum3=1
for i = 1 to n
sum2 = 1
for j = 1 to i
sum2 = sum2 * j
sum3=sum2^(-1)
next j
sum1 = sum1 + sum3
next i
label1.caption = label1.caption + str(sum1)
end sub
需要一个button 和一个lable,结果在lable上显示
- 2楼网友:时间的尘埃
- 2021-02-07 01:00
Private Sub Form_Load()
Dim a As String
Dim i As Long
Dim sSum As Long
a = InputBox("123", "123", 1)
If IsNumeric(a) Then
For i = 1 To a
sSum = sSum + i
Next
End If
MsgBox sSum
End Sub
- 3楼网友:夜风逐马
- 2021-02-07 00:15
Private Sub Form_Load()
Dim n As Integer
n = Val(InputBox("Input a number", "InputBox", "10"))
MsgBox Fun(n)
End Sub
Private Function Fun(n As Integer) As Integer '递归
If n <= 1 Then
Fun = 1
Else
Fun = n + Fun(n - 1)
End If
End Function
- 4楼网友:归鹤鸣
- 2021-02-06 22:57
input “请输入最大值n" n
s=0
for i=1 to n
s=s+i
next i
print "S=";s
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯