VF常见道编程题

上传人:012****78 文档编号:141914241 上传时间:2020-08-14 格式:DOC 页数:28 大小:120KB
返回 下载 相关 举报
VF常见道编程题_第1页
第1页 / 共28页
VF常见道编程题_第2页
第2页 / 共28页
VF常见道编程题_第3页
第3页 / 共28页
VF常见道编程题_第4页
第4页 / 共28页
VF常见道编程题_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《VF常见道编程题》由会员分享,可在线阅读,更多相关《VF常见道编程题(28页珍藏版)》请在金锄头文库上搜索。

1、VF常见道编程题 作者: 日期:1、求解AX2+BX+C=0的根、其中A、B、C三个参数由键盘输入。一元二次方程的求根公式是:X=-bb-4ac/2acleartext 一元二次方程求解 ax2+bx+c=0endtextinput 请输入a的值: to ainput 请输入b的值: to binput 请输入c的值: to cm=b*b-4*a*cif m=0 x1=(-b+sqrt(m)/(2*a) x2=(-b-sqrt(m)/(2*a) ?x1的值是:,x1 ?x2的值是:,x2 else ?此方程无实根!endif2、编写程序将1-100之间所有能被7和3整除的整数输出clearfo

2、r i=1 to 100 if i%3=0 and i%7=0 ?i endifendfor3、编写程序计算e,e的近似值计算公式为:e=1+1/1!+1/2!+1/3!+.+1/n!,直到1/n!0.000001为止cleare=1n=1do while .t. k=1 for i=1 to n k=k*i endfor m=1/k e=e+m if m0.000001 exit endif n=n+1enddo?e=1+1/1!+1/2!+1/3!+1/n!=,e4、编写程序,计算1!+2!+3!+.N!=?clearinput 请输入n的值: to ns=0t=1for i=1 to n

3、 t=t*i s=s+tendfor?1!+2!+3!+.N!=,s5、从键盘输入十个数,将它们进行降序排列。cleardime a(10)for i=1 to 10 input 请输入一个数: to a(i)endfor?降序排列为:for i=1 to 9 for j=i+1 to 10 if a(i)a(j) k=a(i) a(i)=a(j) a(j)=k endif endfor ?alltrim(str(a(i)+ endfor?alltrim(str(a(i)6、(1)输出有*号组成的图形: * * *clearfor i=-3 to 3 ?space(abs(i) for j=1

4、 to 7-abs(i)*2 ?* endforendfor(2) *clearfor i=1 to 5 ?space(5-i) for j=1 to 2*i-1 ?* endforendfor7、编写一个程序产生一个有20项的Fibonacci数列并输出。注:Fibonacci数列的前两项为1,从第三项开始每一项是其前两项只和。cleara=1b=1?a,bfor i=1 to 18 c=a+b a=b b=c ?cendfor8、九九乘法表clearfor i=1 to 9 for j=1 to i ?alltrim(str(i)+*+alltrim(str(j)+=+alltrim(st

5、r(i*j)+space(3) endfor ?Endfor9、显示1100之间的所有素数,并求它们的和。clears=0?1到100之间的素数为:for i=2 to 100 x=0 for j=2 to i-1 if i/j=int(i/j) x=1 endif endfor if x=0 ?alltrim(str(i)+ s=s+i endif endfor?它们的和是:,s10、求100到999之间的水仙花数。clear?100-999之间的水仙花数有:for i=100 to 999 k=int(i/100) m=(int(i/10)%10 n=i%10 if k3+m3+n3=i

6、?alltrim(str(i)+space(2) endifendfor11、从键盘输入10个数,找出其中的最大数和最小数。clearinput 请输入第1个数: to ak=afor i=2 to 10 input 请输入第+alltrim(str(i)+个数: to b if ab k=b endifendfor?其中最大的数是:,a?其中最小的数是:,k12、从键盘输入一个字符串,统计其中各个字符的个数,包括数字,大小写英文字母和特殊字符。clearaccept 请输入一串字符: to xstore 0 to dyw,xyw,kg,sz,qtm=len(x)for i=1 to m x1

7、=substr(x,i,1) k=asc(x1) do case case k=32 kg=kg+1 case k=48 and k=65 and k=97 and k0 b=a%2 a=int(a/2) s=alltrim(str(b)+senddo?转换为二进制为:,s14、VFP编程:有一个34的矩阵,要求编程求出其中值最大的那个元素的值,以及其所在的位置。cleardime a(3,4)for i=1 to 3 for j=1 to 4 input 请输入一个值: to a(i,j) endforendfork=a(1,1)for m=1 to 3 for n=1 to 4 r=a(m

8、,n) if rk k=r x1=m x2=n endif endforendfor?其中最大的值是:,k?它所在的位置是第+alltrim(str(x1)+行,第+alltrim(str(x2)+列15、求1000到10000之间的回文数(1001、3883、4554、7007、9999等),并求它们的和。clears=0?1000到10000之间的回文数有:for i=1000 to 10000 m=alltrim(str(i) zx= dx= for j=1 to 4 zx=zx+substr(m,j,1) dx=dx+substr(m,5-j,1) endfor if zx=dx ?m

9、+space(3) s=s+i endifendfor?它们的和是:,s16、(1)输入两个数,求它们的最大公约数。clearinput 请输入第1个数: to ainput 请输入第2个数: to bc=min(a,b)do while c0 if a%c=0 and b%c=0 s=c exit endif c=c-1enddo?它们的最大公约数是:,s(2)输入两个数,求它们的最小公倍数。clearinput 请输入第1个数: to ainput 请输入第2个数: to bc=max(a,b)do while .t. if c%a=0 and c%b=0 s=c exit endif c

10、=c+1enddo?它们的最小公倍数是:,s17、求s=a+aa+aaa+aaaa.+aaaaaaa.a (n个a) ,a是一个数字,n和a用键盘键入clearinput 请输入a的值: to ainput 请输入n的值: to nk=as=afor i=2 to n k=a*10(i-1)+k s=s+kendfor?s=a+aa+aaa+aaaa.+aaaaaaa.a (n个a)=,s18、用vf求100以内的所有完数clear?1到100内的所有完数为:for i=1 to 100 s=0 for j=1 to int(i/2) if i%j=0 s=s+j endif endfor if s=i ?i endifendfor19、用vf求s=1+1/2+2/3+3/5+.,前10项之和clears=1a=1b=1for i=1 to 9 c=a+b a=b b=c k=a/b s=s+kendfor?s=1+1/2+2/3+3/5+.,前10项之和是:,s20、1/2+2/3+3/5+5/8+.,前20项之后cleara=1b=2s=0for i=1 to 20 s=s+a/b c=a+b a=b b=cendfor?1/2+2/3+3/5+5/8+.的前20项之后为:,s

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号