=1andy=1andra=ctod(str(n,4)+str(y,3)+str(r,3))l=year(date())-ns=abs(mod(n,1" />
当前位置:文档之家› Vfp编程例题

Vfp编程例题

Vfp编程例题
Vfp编程例题

Vfp编程例题

1.使用分支结构写出输入出生年,出生月,出生日算出年龄,星座和生肖。

set talk off

clear

publicx,y

set date ymd

input"请输入你的出生年"to n

input"请输入你的出生月"to y

input"请输入你的出生日"to r

if y>=1 and y<=12 and r>=1 and r<=31

a=ctod(str(n,4)+str(y,3)+str(r,3))

l=year(date())-n

s=abs(mod(n,12))

do case

case a>=ctod(str(n,4)-"/01/20") and a<=ctod(str(n,4)-"/02/18")

?"你的星座为:水瓶座"

case a>=ctod(str(n,4)-"/02/19") and a<=ctod(str(n,4)-"/03/20")

?"你的星座为:双鱼座"

case a>=ctod(str(n,4)-"/03/21") and a<=ctod(str(n,4)-"/04/19")

?"你的星座为:白羊座"

case a>=ctod(str(n,4)-"/04/20") and a<=ctod(str(n,4)-"/05/20")

?"你的星座为:金牛座"

case a>=ctod(str(n,4)-"/05/21") and a<=ctod(str(n,4)-"/06/21")

?"你的星座为:双子座"

case a>=ctod(str(n,4)-"/06/22") and a<=ctod(str(n,4)-"/07/22")

?"你的星座为:巨蟹座"

case a>=ctod(str(n,4)-"/07/23") and a<=ctod(str(n,4)-"/08/22")

?"你的星座为:狮子座"

case a>=ctod(str(n,4)-"/08/23") and a<=ctod(str(n,4)-"/09/22")

?"你的星座为:处女座"

case a>=ctod(str(n,4)-"/09/23") and a<=ctod(str(n,4)-"/10/23")

?"你的星座为:天秤座"

case a>=ctod(str(n,4)-"/10/24") and a<=ctod(str(n,4)-"/11/22")

?"你的星座为:天蝎座"

case a>=ctod(str(n,4)-"/11/23") and a<=ctod(str(n,4)-"/12/21")

?"你的星座为:射手座"

case a>=ctod(str(n,4)-"/12/22") and a<=ctod(str(n,4)-"/12/31") or a>=ctod(str(n,4)-"/01/01") and a<=ctod(str(n,4)-"/01/19")

?"你的星座为:摩羯座"

otherwise

?"输入日期格式错误"

endcase

do case

case s=0

?"你属:猴"

case s=1

?"你属:鸡"

case s=2

?"你属:狗"

case s=3

?"你属:猪"

case s=4

?"你属:鼠"

case s=5

?"你属:牛"

case s=6

?"你属:虎"

case s=7

?"你属:兔"

case s=8

?"你属:龙"

case s=9

?"你属:蛇"

case s=10

?"你属:马"

case s=11

?"你属:羊"

endcase

?"你的年龄大约是:"+str(l,3)

else

?"输入的日期有误"

endif

set talk on

return

2.用循环语句写出100到999之间的水仙花数(公式153=1^3+5^3+3^3)

set talk off

clear

a=100

do while a<=999

b=int(a/100)

c=mod(int(a/10),10)

d=mod(a,10)

if a=b^3+c^3+d^3

?a

endif

a=a+1

enddo

set talk on

return

3.用循环写出九九乘法表。

set talk off

clear

for x=1 to 9

for y=1 to x

z=x*y

??str(y,1)+"*"+str(x,1)+"="+str(z,2)+" "

endfor

?

endfor

set talk on

return

4.用循环语句写出100以内的素数个数及素数是多少。

set talk off

clear

c=0

for x=2 to 100

i=sqrt(x)

for y=2 to i

ifx%y=0

exit

endif

endfor

if y>i

c=c+1

?x

else

endif

endfor

?"100以内的素数的个数为:",c

set talk on

return

5.输入两个数,并算出其最小公倍数,最大公因数,并询问用户是否继续查询。

set talk off

clear

do while .t.

input"请输入一个正整数:"to x

input"请输入一个正整数:"to y

l=max(x,y)

for i=l to x*y

if mod(i,x)=0 and mod(i,y)=0

b=i

c=x*y/b

exit

endif

endfor

?"最小公倍数="+alltrim(str(b)),"最大公约数=",alltrim(str(c)) wait "是否要继续查询(Y/N)" windows to a

if upper (a)="N"

exit

endif

enddo

set talk on

return

6.用循环求100到999之间的回文数。

set talk off

clear

n=0

for x=100 to 999

y=mod(x,10)

z=int(x/100)

if y=z

?x

n=n+1

endif

endfor

?"100到999之间的回文数的个数有:",alltrim(str(n))

set talk on

return

相关主题
文本预览
相关文档 最新文档