VB产生10个[1,100]的随机数
程序运行后在一个标签内产生10个[1,100]的随机数,单击统计按钮后,在4个文本框内分别输出10个数中最大数,最小数,和,平均数。急用!!谢谢!!!!!...
程序运行后在一个标签内产生10个[1,100]的随机数,单击统计按钮后,在4个文本框内分别输出10个数中最大数,最小数,和,平均数。
急用!!谢谢!!!!! 展开
急用!!谢谢!!!!! 展开
4个回答
展开全部
假设标签Label1
文本框Text1 Text2 Text3 Text4
统计按钮Command1
窗体代码
Option Explicit
Private Sub Command1_Click()
Dim Vs() As Long, Ls() As String, fo As Long, Vc As Long
Dim Max As Long, Min As Long, e As Double,t as long
ReDim Vs(Len(Label1))
Ls = Split(Label1, vbCrLf)
For fo = 0 To UBound(Ls)
If IsNumeric(Ls(fo)) Then
Vs(Vc) = Val(Ls(fo))
If Vc = 0 Then Max = Vs(0): Min = Vs(0)
If Max < Vs(Vc) Then Max = Vs(Vc)
If Min > Vs(Vc) Then Min = Vs(Vc)
Vc = Vc + 1
End If
Next
If Vc Then
ReDim Preserve Vs(Vc - 1)
For fo = 0 To Vc - 1
e = e + Vs(fo) / Vc
t=t+vs(fo)
Next
End If
Text1 = "最大" & Max
Text2 = "最新" & Min
Text3="和"& t
Text4 = "平均" & Round(e, 6)
End Sub
Private Sub Form_Load()
Dim fo As Long
Randomize Timer
For fo = 1 To 10
Label1 = Label1 & Rand(1, 100) & vbCrLf
Next
Label1.Height = TextHeight("") * 10
End Sub
Function Rand(Left As Long, Right As Long) As Long
Rand = Left + (Right - Left) * Rnd
End Function
文本框Text1 Text2 Text3 Text4
统计按钮Command1
窗体代码
Option Explicit
Private Sub Command1_Click()
Dim Vs() As Long, Ls() As String, fo As Long, Vc As Long
Dim Max As Long, Min As Long, e As Double,t as long
ReDim Vs(Len(Label1))
Ls = Split(Label1, vbCrLf)
For fo = 0 To UBound(Ls)
If IsNumeric(Ls(fo)) Then
Vs(Vc) = Val(Ls(fo))
If Vc = 0 Then Max = Vs(0): Min = Vs(0)
If Max < Vs(Vc) Then Max = Vs(Vc)
If Min > Vs(Vc) Then Min = Vs(Vc)
Vc = Vc + 1
End If
Next
If Vc Then
ReDim Preserve Vs(Vc - 1)
For fo = 0 To Vc - 1
e = e + Vs(fo) / Vc
t=t+vs(fo)
Next
End If
Text1 = "最大" & Max
Text2 = "最新" & Min
Text3="和"& t
Text4 = "平均" & Round(e, 6)
End Sub
Private Sub Form_Load()
Dim fo As Long
Randomize Timer
For fo = 1 To 10
Label1 = Label1 & Rand(1, 100) & vbCrLf
Next
Label1.Height = TextHeight("") * 10
End Sub
Function Rand(Left As Long, Right As Long) As Long
Rand = Left + (Right - Left) * Rnd
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a(10) As Integer
Min = 100: Max = 1
For i = 1 To 10
Randomize
a(i) = Int(Rnd(1) * 100 + 1)
Label1.Caption = Label1.Caption & Str(a(i))
Sum = Sum + a(i)
If a(i) > Max Then Max = a(i)
If a(i) < Min Then Min = a(i)
Next
Text1 = Max
Text2 = Min
Text3 = Sum
Text4 = Sum / 10
Min = 100: Max = 1
For i = 1 To 10
Randomize
a(i) = Int(Rnd(1) * 100 + 1)
Label1.Caption = Label1.Caption & Str(a(i))
Sum = Sum + a(i)
If a(i) > Max Then Max = a(i)
If a(i) < Min Then Min = a(i)
Next
Text1 = Max
Text2 = Min
Text3 = Sum
Text4 = Sum / 10
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim a&,b&()
dim max&
dim min&
dim sum&
dim aver&
for a=1 to 10
b(a)=int(rnd*100)+1
sum=sum+b(a)
label1.caption=label1.caption & trim(str(b(a)))
next
aver=sum/10
max=b(1)
min=b(1)
for a=1 to 10
if max<b(a) then max=b(a)
if min>b(a) then min=b(a)
next
text1.text=max
text2.text=min
text3.text=sum
text4.text=aver
dim max&
dim min&
dim sum&
dim aver&
for a=1 to 10
b(a)=int(rnd*100)+1
sum=sum+b(a)
label1.caption=label1.caption & trim(str(b(a)))
next
aver=sum/10
max=b(1)
min=b(1)
for a=1 to 10
if max<b(a) then max=b(a)
if min>b(a) then min=b(a)
next
text1.text=max
text2.text=min
text3.text=sum
text4.text=aver
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ty
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询