knrt.net
当前位置:首页 >> vB 编写一个具有可选参数的函数过程,既可以求两个数的最大值,也可以求三个数的最大值, >>

vB 编写一个具有可选参数的函数过程,既可以求两个数的最大值,也可以求三个数的最大值,

Function max(n1, n2, Optional n3 = Empty) max = IIf(Val(n1) > Val(n2), Val(n1), Val(n2)) If Not IsEmpty(n3) Then max = IIf(Val(n3) > max, Val(n3), max) End Function Private Sub Command1_Click() Print "23.567与76.3的最大值是" & max(23.567, 76.3) Print "1895、568与9816的最大值是" & max(1895, 568, 9816) End Sub

1、冒泡法排序后输出最大值和最小值dim ssnum=val(inputbox ("输入要求的数的个数"))dim a(1 to num) for i=1 to numa(i)=texti.textnextfor m=num to 2for n=1 to m-1if a(n)>=a(n+1) thenss=a(n+1)a(n+1)=a(n)a(n)=ssend ifnextnextprint "

function max1(val1,val2) if val1>val2 then max1=val1 else max1=val2 end function function min1(val1,val2) if val1>val2 then min1=val2 else min1=val1 end function 不管比较多少个数,都是从两个数比较做起 可以迭代这个函数即可 s1=max1(max1(34,23),47) 即为求三个数的最大数

这是3个的dim maxx as doublefunction max(x as double, y as double)if x > y thenmax = xelsemax = yend ifend functionprivate sub command1_click()dim a(1 to 3) as doublea(1) = 2225a(2) = 12a(3) = 48for i = 1 to 3maxx = max(a(i), maxx)nextprint maxxend sub

先编写一个求两个数中最大值的函数,然后输入四个数,利用前面的函数做三次比较,第一次比较num1和num2,第二次比较num3和num4,第三次比较前两次得到的两个较大数,得出最后的四个数中最大的数. 楼主说的是这个意思吧?如果是这个意思的话程序如下 #include int max(int x,int y){ return x>y?x:y; } void main(){ cout>a>>b>>c>>d; cout

Private Function MaxValue(v()) As Integer On Error Goto hErr MaxValue = v(0) For i = 1 to Ubound(v)'遍历数组中的所有元素 If val(v(i)) > MaxVlue Then MaxValue = v(i) '如果第i个元素大于maxvalue那么就将maxvalue设为它. Next iExit FunctionhErr:

这是3个的Dim maxx As DoubleFunction max(x As Double, y As Double)If x > y Thenmax = xElsemax = yEnd IfEnd FunctionPrivate Sub Command1_Click()Dim a(1 To 3) As Doublea(1) = 2225a(2) = 12a(3) = 48For i = 1 To 3maxx = max(a(i), maxx)NextPrint maxxEnd Sub

Private Sub Command1_Click()Dim a, ba = Val(InputBox("a="))b = Val(InputBox("b="))Print a, bCall bj(a, b)End SubSub bj(a, b) If a > b Then Print "a>b" ElseIf a < b Then Print "a<b" Else Print "a=b" End IfEnd Sub

Private Sub Command1_Click() Dim I As Integer Dim N(15) As Integer, M As Integer Randomize For I = 1 To 15 N(I) = Int(Rnd * 1000) '随机产生1000以内正整数 Print N(I); Next Print M = N(1) For I = 2 To 15 M = P(N(I), M) Next Print "最大值为:"

Private Sub Form_Load()Dim a(2) As SingleDim b(4) As SingleDim c(6) As Singlea(0) = InputBox("请输入第一个数(共3个):")b(0) = a(0)c(0) = a(0)a(1) = InputBox("请输入第二个数(共3个):")b(1) = a(1)c(1) = a(1)a(2) =

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com