谁帮我用asp写个函数,比如有一组数:
aa=1125
bb=2548
cc=8755
dd=1254
求出 max(aa,bb,cc,dd)中最大的那个和min(aa,bb,cc,dd)中最小的那个,谢谢!!
------解决方案--------------------
<%@Language= "VBScript "%>
<%
Function Max(Max_location_s)
Dim Max_location_a, Max_location_i, Max_location_n
Max_location_a = Split(Max_location_s, ", ")
Max_location_n = Max_location_a(0)
For Max_location_i = 1 To UBound(Max_location_a)
If Eval(Max_location_n) < Eval(Max_location_a(Max_location_i)) Then Max_location_n = Max_location_a(Max_location_i)
Next
Max = Max_location_n
End Function
Function Min(Min_location_s)
Dim Min_location_a, Min_location_i, Min_location_n
Min_location_a = Split(Min_location_s, ", ")
Min_location_n = Min_location_a(0)
For Min_location_i = 1 To UBound(Min_location_a)
If Eval(Min_location_n) > Eval(Min_location_a(Min_location_i)) Then Min_location_n = Min_location_a(Min_location_i)
Next
Min = Min_location_n
End Function
a = 1
b = 2
c = 3
d = 4
e = 5
Response.Write Max( "a,b,c,e,d ") '注意要把要判断的变量用 "包起来,并且用,区分
Response.Write " <hr /> "
Response.Write Min( "a,b,c,e,d ")
%>
------解决方案--------------------
Function Max(a)
Dim i, m
If UBound(a) > 0 Then
m = a(0)
For i = 1 To UBound(a)
If a(i) > m Then m = a(i)
Next
Max = m
Else
Max = Null
End If
End Function
Function Min(a)
Dim i, m
If UBound(a) > 0 Then
m = a(0)
For i = 1 To UBound(a)
If a(i) < m Then m = a(i)
Next
Min = m
Else
Min = Null
End If
End Function
Dim ary
ary = Array(2, 3, 1)
Response.Write Max(ary)
Response.Write " <hr /> "
Response.Write Min(ary)