相互学习,互相交流,共同提高。
SET ESCAPE OFF
CLEAR
LOCAL str1
input '请输入一个正整数:' to n
CLEAR
WAIT WINDOW '按 ESC 退出...' nowait
DIMENSION arr1(n)
STORE 9 TO arr1
DO whil .t.
str1=prg1(@arr1)
IF str1==REPLICATE("0",ALEN(arr1))
EXIT
ELSE
?str1
ENDIF
IF INKEY()=27
EXIT
ENDIF
ENDDO
WAIT CLEAR
RETURN
FUNCTION prg1(arr1)
LOCAL i1,i2,i3,str1
i1=ALEN(arr1)
str1=''
FOR i2=1 TO i1
str1=str1+TRANSFORM(arr1[i2])
ENDFOR
IF str1<>REPLICATE("0",i1)
IF arr1[i1]=0
arr1[i1]=9
FOR i3=i1-1 TO 1 STEP -1
IF arr1[i3]=0
arr1[i3]=9
ELSE
arr1[i3]=arr1[i3]-1
EXIT
ENDIF
ENDFOR
ELSE
arr1[i1]=arr1[i1]-1
ENDIF
ENDIF
RETURN str1
ENDFUNC