求助vb代码编写,谢谢!!!
一、单击窗体,实现下述功能:利用随机函数Rnd产生n个随机两位数(整数),显示在窗体上(一行),然后再第二行输出这10个数中的最大值和平均值。(利用InputBox函数输入n)
二、先在窗体上添加两个文本框、两个标签和一个命令按钮。编程实现:单击命令按钮,在两个标签中分别显示两个文本框中两个数的最大公约数和最小公倍数。
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(9) As Integer, i%, max%, avg! label1.text = "" For i = 0 To 9 a(i) = Int(Rnd() * 90 + 10) Label1.Text &= a(i) & "" Next max = a(0) avg = a(0) For i = 1 To 9 If a(i) > max Then max = a(i) avg += a(i) Next avg /= 10 Label1.Text &= vbCrLf & "max=" & max & "avg=" & avg End Sub End Class这个是10个数的
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n As Long Dim na() As Long Dim max As Long Dim avg As Double Dim i As Integer n = InputBox("please input n") If n = 0 Then Exit Sub ReDim na(0 To n) Randomize() For i = 1 To n na(i) = Int(Rnd() * 90) + 10 If na(i) > max Then max = na(i) avg = avg + na(i) Next avg = avg / n For i = 1 To n Label1.Text &= na(i) & " " Next Label1.Text &= vbCrLf & "max is " & max & vbCrLf & "avg is " & avg End Sub End Class这个是n个数的