我将此写成了一个函数,该函数要求 有5个参数,返回最大值,格式
getmax(参数1,参数2,参数3,参数4,参数5)
FUNCTION getmax
LPARAMETERS aa,bb,cc,dd,ee
CREATE TABLE temp (num N(10,4))
INSERT INTO temp (num) VALUES (aa)
INSERT INTO temp (num) VALUES (bb)
INSERT INTO temp (num) VALUES (cc)
INSERT INTO temp (num) VALUES (dd)
INSERT INTO temp (num) VALUES (ee)
SELECT MAX(num) as max_num FROM temp INTO CURSOR tmp
maxnum = tmp.max_num
USE
SELECT temp
USE
DELETE FILE temp.dbf
RETURN maxnum
ENDFUNC
当然,这样写纯粹是为了写vf程序,还可以使用冒泡法等算法实现
将键盘输入的五个数存入数组元素,然后用顺序比较法由大到小排序。
clear
dime a(5)
for i=1 to 5
input to a(i)
endfor
for i=1 to 4
for j=i+1 to 5
if a(i) t=a(i)
a(i)=a(j)
a(j)=t
endif
endfor
endfor
?"五个数由大到小的顺序是:"
for i=1 to 5
??a(i)
endfor
return