VB编程题 3+33+333+......+333333333

来源:百度知道 编辑:UC知道 时间:2024/05/29 22:52:58
简单易懂

s = 0
For i = 1 To 9
a = Val(String(i, "3"))
s = s + a
Next
Print s

Sub a()
Dim ws As Integer '累加多少位3

ws = 9
If ws > 9 Then
MsgBox "运算结果会溢出,位数不得超过9位"
Exit Sub
End If
Dim YZ As Long '原值是多少
Dim JG As Long '结果
Dim i As Integer
JG = 0
YZ = 0
For i = 1 To ws
JG = JG + YZ + 3 * (10 ^ (i - 1))
YZ = YZ + 3 * (10 ^ (i - 1))
Next i
MsgBox JG
End Sub

Private Sub Command1_Click()
s = 0
For i = 1 To 9
a = Val(String(i, "3"))
s = s + a
Next
Print s
End Sub

s=0
for i= 0 to 8
a=i*10+3
s=s+a
next
? s