用VFP编程,任意输入10个数,按从大到小的顺序排列。

如题所述

这是用顺序比较法排序:

clear
dime a(10)
for i=1 to 10
input to a(i)
endfor
for i=1 to 9
for j=i+1 to 10
if a(i)<a(j)
t=a(i)
a(i)=a(j)
a(j)=t
endif
endfor
endfor
?"10个数由大到小的顺序是:"
for i=1 to 10
??a(i)
endfor
return
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-02-29
这是用顺序比较法排序:
clear
dime
a(10)
for
i=1
to
10
input
to
a(i)
endfor
for
i=1
to
9
for
j=i+1
to
10
if
a(i)<a(j)
t=a(i)
a(i)=a(j)
a(j)=t
endif
endfor
endfor
?"10个数由大到小的顺序是:"
for
i=1
to
10
??a(i)
endfor
return
第2个回答  2010-07-05
CLEAR
SET UDFPARMS TO REFERENCE &&地址传递
DIME AAA(10)
FOR i= 1 TO 10
input "请输入第"+ALLTRIM(STR(i))+"个数:" to AAA(i)
NEXT
=MySort(AAA,10) &&调用冒泡排序函数.
i=1
?"从大到小排序结果为:"
do while i<=10
??AAA(i) &&显示排完序后的数据.
i=i+1
enddo
RETURN

*冒泡排序函数.
*参数: pData: 传入数组, nCount:数组的大小.
function MySort
para pData, nCount
for i=1 to nCount
for j=nCount to i+1 step -1
if pData(j)>pData(j-1)
iTemp = pData[j-1]
pData(j-1) = pData[j]
pData(j) = iTemp
endif
endfor
endfor
endfunc