当前位置:文档之家› VFP6.0练习题及答案

VFP6.0练习题及答案

1。

输入一个数,若该数为正数求平方根,若该数为负数求绝对值,若该数为零则直接打印该数,并循环
clea
set talk off
do while .t.
input [请输入一个数:] To n
do case
case n>0
?str(n)+[的平方根为]+str(sqrt(n),7,1)
case n<0
?n,[的绝对值为],abs(n)
case n=0
?[n=],n
endcase
wait '还要加述下一个么?(y/n)' to lj
if lj='y'
loop
else
exit
endif
enddo
set talk on
?[byebye]
return
2。

把百分制成绩转化为:优、良、中、及格、不及格。

CLEA
set talk off
do while .t.
input'请输入一个百分制成绩:' to cj
do case
case cj>100 or cj<0
?'输入错误,请重新输入!'
case cj>=90
?'优秀'
case cj>=80
?'良好'
case cj>=70
?'中等'
case cj>=60
?'及格'
other
?'不及格'
endcase
wait '还要加述下一个么?(y/n)' to xz
if xz='y'
loop
else
exit
endif
enddo
set talk on
?[byebye]
return
3。

编程~画出一个菱形。

clea
set talk off
for i=1 to 4
?spac(20-2*i)+repli('* ',2*i-1) next
for j=4 to 1 step-1
?spac(20-2*j)+repli('* ',2*j-1) next
4。

编写一个组合.
clea
set talk off
inpu'n=' to n
inpu'm=' to m
c=jc(n)/(jc(n-m)*jc(m))
?'c=',c
func jc
para k
t=1
for j=1 to k
t=t*j
endfor
return t
5。

求100之内的奇数和。

方法一:set talk off
s=0
i=1
do while i<100
s=s+i
i=i+2
enddo
?s
return
方法二:set talk off
s=0
for i=1 to 100 step 2
s=s+i
endfor
?[100之内的奇数和为]+str(s,4)
return
6。

九九乘法表
clear
for a=1 to 9
for b=1 to a
??str(b,1)+"x"+str(a,1)+"="+str(b*a,2)+space(2) endfor
?
endfor
7。

输入任意一个三位数,得其逆序。

inpu'请输入一个三位数' to x
c=mod(x,10)
b=int(mod(x,100)/10)
a=int(x/100)
s=c*100+b*10+a
?s
8。

任意输入10个逻辑值,并统计为真的个数。

clea
set talk off
s=0
for i=1 to 10
input'请输入;' to x
if x=.t.
s=s+1
endif
next
?s
9。

腓波那次序列。

方法一:
dime a(40)
a(1)=1
a(2)=1
for i=3 to 40
a(i)=a(i-1)+a(i-2)
next
for j=1 to 40
??a(j)
if mod(j,10)=0
?
endif
next
方法二:
clea
a1=1
a2=1
?a1,a2
for i=1 to 38
a3=a1+a2
a1=a2
a2=a3
??a3
next
10。

口令进入。

clea
set talk off
n=0
for i=1 to 3
accept[请输入口令:] to kl
n=n+1
if kl='123456'
?'欢迎进入本系统!'
exit
else
if n<3
?'口令不正确,请重新输入!'
loop
else
?'非法输入!'
exit
endif
endif
next
11。

计算1~100以内的奇数平方和、偶数立方和。

clea
set talk off
s1=0
s2=0
for i=1 to 100
if mod(i,2)=1 s1=s1+i^2 else
s2=s2+i^3 endif
next
?s1,s2。

相关主题