CLEAR
ACCEPT "请输入字串:" TO a
b=0
c=0
d=0
e=0
f=0
n = LEN(a)
FOR i = 1 TO n
x=ASC(SUBSTR(a, i, 1))
DO CASE
CASE (x >= 65 AND x =<90) OR (x >= 97 AND x =<122) &&字母
b=b+1
CASE x = 32 &&空格
c=c+1
CASE x >= 48 AND x =<57 &&数字
d=d+1
OTHERWISE
f=f+1
ENDCASE
ENDFOR
? "字串:", a
? "字母:", b," 空格:",c," 数字:",d," 其他:",f
&&方案二:
CLEAR
ACCEPT "请输入字串:" TO a
STORE 0 TO b,c,d,e,f
n = LEN(a)
FOR i = 1 TO n
x=SUBSTR(a, i, 1)
DO CASE
CASE ISALPHA(x) &&字母
b=b+1
CASE ISBLANK(x) &&空格
c=c+1
CASE ISDIGIT(x) &&数字
d=d+1
OTHERWISE
f=f+1
ENDCASE
ENDFOR
? "字串:", a
? "字母:", b," 空格:",c," 数字:",d," 其他:",f
n=0?"1000以内的完数有:"
for i=1 to 1000
s=0
for j=1 to i-1
if i%j=0
s=s+j
endif
endfor
if s=i
n=n+1
??i
endif
endfor
?"完数个数是:",n
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)