vb.net求最大值,vb中求最大值最小值
vb。net中的最大值及最小值函数的编写
'vb.net2008
网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了船山免费建站欢迎大家使用!
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim min, max As Integer
Dim a() As Integer = {3, 2, 4, 1}
min = Proc(a)(0)
max = Proc(a)(1)
End Sub
Private Function Proc(ByVal a() As Integer)
Dim a_out(a.GetUpperBound(0)), a_m(1) As Integer
System.Array.Copy(a, a_out, a.GetUpperBound(0) + 1)
System.Array.Sort(a_out)
a_m(0) = a_out(0)
a_m(1) = a_out(a_out.GetUpperBound(0))
Return a_m
End Function
End Class
请教各位一个VB.NET的问题 找出两个最大数字
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim numList As New List(Of Integer), str As String = ""
Dim strArr() As String = TextBox1.Text.Split(New Char() {" "c, ","c, "."c, Chr(13)}, StringSplitOptions.RemoveEmptyEntries)
For Each unitStr As String In strArr
If IsNumeric(unitStr) Then
numList.Add(CInt(unitStr))
Else
str = unitStr " "
End If
Next
numList.Sort()
Label1.Text = numList.Count "个数字被输入"
Label2.Text = "最大的数字是" numList(numList.Count - 1)
If numList.Count 1 Then Label2.Text = ",第二大数字是" numList(numList.Count - 2)
Label3.Text = str
End Sub
用vb.net求三个数中的最大值以及最小值函数的编写
MaxOrMin 指示返回最大还是最小.
Private Function Math(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As Integer, ByVal MaxOrMin As Short) As Integer
Dim s() As Integer = {num1, num2, num3}
Dim max, min As Integer
If s(0) s(1) Then
min = s(0)
max = s(1)
End If
If s(1) s(2) Then
min = s(1)
max = s(2)
End If
If MaxOrMin = 0 Then Return max
If MaxOrMin = 1 Then Return min
End Function
vb.net程序,利用随机函数产生100个1到100之间的整数,求其中的最大最小值。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Randomize() '产生随机数种子 以防止每次生成结果都一样
Dim a(100) As Integer '声明数组存放数据 用来保存随机数结果
Dim max As Integer, min As Integer '声明两个变量存最大值和最小值
min = 1000 : max = 0 '设置初值
For i = 0 To 99 '循环100次
a(i) = Int(Rnd() * 1000 + 1) '用rnd生成一个随机数 由于rnd范围为0-1之间的小数.所以*1000设置他的范围为0到999之间 加1变成1到1000之间
If a(i) = max Then max = a(i) '如果当前数值大于最大值的变量就保存
If a(i) = min Then min = a(i) '如果当前数值小于最小值的变量就保存
Next
MsgBox("最大值为" max)
MsgBox("最小值为" min)
End Sub
网页名称:vb.net求最大值,vb中求最大值最小值
本文来源:http://azwzsj.com/article/pheojc.html