一·实验目的
实现十个数的大小比较,最终输出最大的一个数。
二·实验内容
在对象窗口划出一个command按钮,点击command按钮输入以下vb程序语言:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim max As Integer
Dim c As Integer
Dim d As Integer
Dim f As Integer
Dim g As Integer
Dim h As Integer
Dim i As Integer
Dim j As Integer
a = 45
b = 78
c = 123
d= 136
e=98
f=456
g=32
h=76
i=57
j=145
If a > b Then
max = a
Else
max = b
End If
If c > max Then
max = c
End If
If d> max Then
max = d
End If
If e > max Then
max =e
End If
If f > max Then
max =f
End If
If g> max Then
max = g
End If
Ifh > max Then
max = h
End If
If i > max Then
max = i
End If
If j > max Then
max =j
End If
Print max
End Sub
点击运行即可。
但是,如果采用循环语句我这个程序就会出现问题。
采用循环与依据如下:
dim a as integer
dim b as integer
dim f(i) as integer
if a>b then
max=a
else
max=b
end if
for i=0 to 7=int (rnd*100)
if f(i)> max then
max=f(i)
end if
点击运行,却出现错误
三·心得体会
尽管出现了问题,但是我学会了开动脑筋解决问题。
四·遇到的问题及解决方法
从三个数的大小比较到十个数的大小比较,有一定的难度,没有想到用循环的方法,通过老师的提点,采用了循环,但是没有能够成功。
五·没有解决的问题
采用循环的方法但是没能够运行成功,并且,没能找到所出现的问题,望老师提点。