vb程序编写,计算5+55+555+5555+5555+……前n项的和,用do while loop语句编写
1个回答
展开全部
新建一工程,在窗体上拖入一个按钮,一个label控件。
Option Explicit
Private Sub Command1_Click()
Dim I As Long, J As Long, K As Long
Dim S As Long, T As String
J = Val(InputBox("请输入要计算的次数:", "数据输入:", "5"))
If J < 1 Then Exit Sub
If J > 8 Then MsgBox "超过程序变量最大值"
I = 1
Do While I <= J
T = ""
For K = 1 To I
T = T & "5"
Next K
S = S + CLng(T)
I = I + 1
Loop
Label1.Caption = "5+55+...,连续加" & J & "次的结果是" & S
End Sub
Private Sub Form_Load()
Label1.Caption = "5+55+...,连续加N次的结果是?"
End Sub
运行效果图如下:
更多追问追答
追问
能用
do while
loop
的循环结构吗,作业要求
追答
你难道连这都没发现吗? 代码里你看能找到不?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询