一、 程序填空
一、 程序填空
1. 输入一串数字字符,当其个数为10时,进行各个数字求和运算,否则重新输入.
CLEAR
SET TALK OFF
S=0
DO WHILE .T.
ACCEPT “输入一串数字字符:” TO X
M= (1)
IF M=10
(2)
ENDIF
(3)
ENDDO
FOR N=1 TO 10
S=S+ (4)
ENDFOR
”该数字字符各个数字之和为:”,S
SET TALK ON
RETURN
2. 定义一个包含10个元素的A数组,该数组中已有9个数据且按从小到大顺序存放,第10个元素为空,现输入一个数放到数组中,且要求仍为由小到大顺序.
CLEAR
SET TALK OFF
DIME A(10)
FOR K=1 TO 9
INPUT "输入"+ "第"+STR(K,2)+ "个数据" TO A(K)
NEXT
INPUT “输入要插入的数:” TO X
FOR N=1 TO 9
IF A(N)>X
(5)
ENDIF
ENDFOR
FOR M=10 TO N+1 (6)
(7)
NEXT
(8)
FOR K=1 TO 10
A(K)
ENDFOR
SET TALK ON
RETURN
&&这是测试过的程序,请你再测试.
&&1.
CLEAR
SET TALK OFF
S=0
DO WHILE .T.
ACCEPT "输入一串数字字符:" TO X
M=LEN(x)
IF M=10
exit
ENDIF
loop
ENDDO
FOR N=1 TO 10
S=S+VAL(SUBSTR(x,n,1))
ENDFOR
"该数字字符各个数字之和为:",S
SET TALK ON
RETURN
&&2.
CLEAR
SET TALK OFF
DIME A(10)
FOR K=1 TO 9
INPUT "输入"+ "第"+STR(K,2)+ "个数据" TO A(K)
NEXT
INPUT "输入要插入的数:" TO X
FOR N=1 TO 9
IF A(N)>X
exit
ENDIF
ENDFOR
FOR M=10 TO N+1 STEP -1
a(m) =a(m-1)
NEXT
a(N)=x
FOR K=1 TO 10
A(K)
ENDFOR
SET TALK ON
RETURN