怎样用VFP编写一个比较五个数大小的程序
2个回答
展开全部
我将此写成了一个函数,该函数要求 有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程序,还可以使用冒泡法等算法实现
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)<a(j)
t=a(i)
a(i)=a(j)
a(j)=t
endif
endfor
endfor
?"五个数由大到小的顺序是:"
for i=1 to 5
??a(i)
endfor
return
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)<a(j)
t=a(i)
a(i)=a(j)
a(j)=t
endif
endfor
endfor
?"五个数由大到小的顺序是:"
for i=1 to 5
??a(i)
endfor
return
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询