请帮忙做几道VB题目,急求!
2.输入一个正整数,然后计算不大于该数的所有自然数的平方和。3.我国现有13亿人口,按人口年增长0.8%计算,多少年后我国人口超过26亿。4.输入10个数,求出其中最大值...
2. 输入一个正整数,然后计算不大于该数的所有自然数的平方和。
3. 我国现有13亿人口,按人口年增长0.8%计算,多少年后我国人口超过26亿。
4. 输入10个数,求出其中最大值和最小值。 展开
3. 我国现有13亿人口,按人口年增长0.8%计算,多少年后我国人口超过26亿。
4. 输入10个数,求出其中最大值和最小值。 展开
1个回答
展开全部
2. Dim a As Integer, i As Integer, sum As Integer
sum = 0
If Text 1.Text = "" Then
MsgBox("请输入一个正整数!")
Exit Sub
Else
a = Text 1.Text
End If
For i = 0 To a - 1
If sum = 0 Then
sum = i ^ 2
Else
sum = sum + i ^ 2
End If
Next
Text 2.Text = sum
End Sub
3.Dim x As Integer, i As Integer
x = 13
i = 0
Do While x < 26
x = x * (1 + 0.008)
i = i + 1
Loop
Text 1.Text = i
4.Dim i As Integer, j As Integer
Dim min As Integer, max As Integer
Dim ar(10) As String
For i = 0 To 9
MsgBox("请输入第" & Str(i + 1) & "个数字")
ar(i) = Val(InputBox("请输入")) '将输入的数据转换为数值型
Next
min = ar(0)
max = ar(0)
For i = 1 To 9
If min > ar(i) Then
min = ar(i)
End If
Next
For j = 1 To 9
If max < ar(j) Then
max = ar(j)
End If
Next
TextBox1.Text = max
TextBox2.Text = min
sum = 0
If Text 1.Text = "" Then
MsgBox("请输入一个正整数!")
Exit Sub
Else
a = Text 1.Text
End If
For i = 0 To a - 1
If sum = 0 Then
sum = i ^ 2
Else
sum = sum + i ^ 2
End If
Next
Text 2.Text = sum
End Sub
3.Dim x As Integer, i As Integer
x = 13
i = 0
Do While x < 26
x = x * (1 + 0.008)
i = i + 1
Loop
Text 1.Text = i
4.Dim i As Integer, j As Integer
Dim min As Integer, max As Integer
Dim ar(10) As String
For i = 0 To 9
MsgBox("请输入第" & Str(i + 1) & "个数字")
ar(i) = Val(InputBox("请输入")) '将输入的数据转换为数值型
Next
min = ar(0)
max = ar(0)
For i = 1 To 9
If min > ar(i) Then
min = ar(i)
End If
Next
For j = 1 To 9
If max < ar(j) Then
max = ar(j)
End If
Next
TextBox1.Text = max
TextBox2.Text = min
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询