您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 趣味Visual-FoxPro--程序设计集锦
趣味VisualFoxPro程序设计集锦5.舍罕王的失算settalkoffinput[请输入n:]tont=1s=1fori=2tont=t*2s=s+tendforv=s/1.42e8h=(9/3.14159*v)^(1/3)?总麦粒数约为:+str(s,10,3)+粒.?折合体积约为:+ltrim(str(v,15))+立方米?堆成正圆锥高约为:+str(h,5)+米return程序运行结果与说明请输入n:64总麦粒数约为:1.845e+019折合体积约为129906648406立方米堆成正圆维高约为7193米5-1失算的另一名题:买马灯input请输入n:tont=1s=1fori=2tont=t*2s=s+tendfor?共需花费+ltrim(str(s,16))+个包卢斯卡.?合约+str(s/400,10,4)+卢卡.return程序运行结果与点评请输入n:24共需花费1677215个外包卢斯卡合约41943.0375卢布6分数不等式?求n1+1/2+1/3+1/4+...+1/mn+1的正整数msettalkoffsetdecito14input请输入n:toni=0s=0dowhilesni=i+1s=s+1/ienddoc=idowhilesn+1i=i+1s=s+1/ienddod=i-1?满足不等式的m为:+ltrim(str(c,10))+m+ltrim(str(d,10))return程序运行结果:求n1+1/2+1/3+1/4….+1/mn+1的正整数m请输入n:10满足不等式的m为:12367m33616请输入n:15满足不等式的m为:1835421m49891907阶乘与阶乘和数settalkoff?三位阶乘和数有:form=100to999a=int(m/100)b=mod(int(m/10),10)c=mod(m,10)ifm=jc(a)+jc(b)+jc(c)??mendifendforreturnfuncjcparaxp=1fori=1toxp=p*iendforreturnp程序运行结果:三位阶乘和数有:145可见145是唯一的三位阶乘和数8综合高精度计算cleardimea(500)a=0?1:计算阶乘n!?2:计算乘方m^n?3:计算排列数A(n,m)input选择(1-3):tozinput请输入正整数n:tonifz#1input请输入正整数m(m=n):tomendifd=500t=1ifz=3t=n-m+1endifa(1)=1fori=ttonifz=2b=melseb=iendiff=0forj=1todx=a(j)*b+ff=int(x/10)a(j)=x%10endforendforj=ddowhilea(j)=0j=j-1enddof=jdocasecasez=1?str(n,8)+!=casez=2?str(m,6)+^+ltrim(str(n))+=casez=3?A(+ltrim(str(n))+,+ltrim(str(m))+)=endcased=0forj=fto1step-1d=d+1??str(a(j),1)ifd%50=0?space(10)endifendfor?所得结果共+ltrim(str(f))+位return运行程序,选择3,输入n=100,m=90,得A(100,90)=257182031095525112107857249934597388918419224714455526533820998388496472644482792132224051962512451185663850094630284343341744128000000000000000000000000所得结果共152位。10最大公约数与最小公倍数settalkoffinput输入正整数a:toainput输入整数b:tobst=ltrim(str(a,12))+,+ltrim(str(b,12))m=a*br=mod(a,b)dowhiler#0a=bb=rr=mod(a,b)enddo?(+st+)=+ltrim(str(b,15))?(+st+)=+ltrim(str(m/b))return运行程序,输入1104,1272得(1104,1272)=24{1104,1272}=5851211水仙花数settalkoffinput输入正整数a:toainput输入整数b:tobst=ltrim(str(a,12))+,+ltrim(str(b,12))m=a*br=mod(a,b)dowhiler#0a=bb=rr=mod(a,b)enddo?(+st+)=+ltrim(str(b,15))?(+st+)=+ltrim(str(m/b))return运行程序,得水仙花数:15337037140712勾股数settalkoffinput请输入区间下限值:tom1inpu请输入区间上限值:tom2?区间[+ltrim(str(m1))+,+ltrim(str(m2))+]中的勾股数组有:n=0fora=2tosqrt(m2)forb=1toa-1if(a+b)%2=0b=b+1endift=0fork=2tobifb%k=0anda%k=0t=1endifendforift=0d=a*a-b*be=2*a*bf=a*a+b*bfori=1tom2/fx=i*dy=i*ez=i*fifxm1orym1orzm2loopendif?str(x)+str(y)+str(z)n=n+1endforendifendforendfor?共+ltrim(str(n))+组勾股数.return运行程序,求得[10,30]中的勾股数:区间(10,30)中的勾股数组有:12162015202518243010242621202913完全数settalkoffinput[x=]toxinput[y=]toy?区间[+ltrim(str(x))+,+ltrim(str(y))+]中的完全数:n=0fora=xtoys=1fork=2toa/2ifa%k=0s=s+kendifendforifs=an=n+1?str(n,3)+:+ltrim(str(a))+-1fork=2toa/2ifa/k=int(a/k)??++ltrim(str(k,5))endifendforendifendforreturn运行程序,输入X=2,Y=100,得区间[2,1000]中的完全数:1:6=1+2+32:28=1+2+4+7+143:496=1+2=4+8+16+31+62+124+24814相亲数settalkofffori=11to9999s=1t=int(sqrt(i)+.01)forj=2totifi%j=0s=s+j+i/jendifendforifi=t*ts=s-tendififiss1=1t=int(sqrt(s)+0.1)forj=2totifs%j=0s1=s1+j+s/jendifendforifs=t*ts1=s1-tendififs1=i?相亲数:+str(i)+str(s)?str(i,5)+的真因数之和为:1forj=2toi/2ifi%j=0??++ltrim(str(j))endifendfor??=+ltrim(str(s))?str(s,5)+的真因数之和为:1forj=2tos/2ifs%j=0??++ltrim(str(j))endifendfor??=+ltrim(str(i))endifendifendforreturn运行程序,得4位以内的相亲数:相亲数:220284220的真因数之和为:1+2+4+5+10+11+20+22+44+55+110=284284的真因数之和为:1+2+4+71+142=220相亲数118412101184的真因数之和为:1+2+4+8+16+32+37+74+148+296+592=12101210的真因数之和为:1+2+5+10+11+22+55+110+121+242+605=1184相亲数262029242620的真因数之和为:1+2+4+5+10+20+131+262+524+655+1310=29242924的真因数之和为:1+2+4+17+34+43+68+86+172+731+1462=2620相亲数502055645020的真因数之和为:1+2+4+5+10+20+251+502+1004+1255+2510=55645564的真因数之和为:1+2+4+13+26+52+107+214+428+1391+2782=5020相亲数623263686232的真因数之和为:1+2+4+8+19+38+41+76+82+152+164+328+779+1558+3116=63686368的真因数之和为:1+2+4+8+16+32+199+398+796+1592+3184=623215守形数settalkoffinput[x=]toxinput[y=]toyfora=xtoys=a*ab=1k=adowhilek0b=b*10k=int(k/10)enddoc=s%bifa=c?ltrim(str(a))+[^2=]+ltrim(str(s))endifendforreturn运行程序,输入X=10,Y=10000得25^2=62576^2=5776376^2=141376625^2=3906259376^2=8790937616素数settalkoff?本程序求区间[c,d]上的素数:input输入区间下限c:tocinput输入区间上限d:tod?区间[+ltrim(str(c))+,+ltrim(str(d))+]上的素数有:n=0ifc%2=0c=c+1endif?fori=ctodstep2t=0forj=3tosqrt(i)step2ifi%j=0t=1exitendifendforift=0??str(i,6)n=n+1ifmod(n,10)=0?endifendifendfor?共+ltrim(str(n))+个素数.return程序运行示例本程序求区间[C,D]上的数数输入区间下限C:2000输入区间上限D:210020032011201720272029203920532063206920812083208720892099共14个素数17乌兰现象settalkoffclearinput请输入数阵的阶数m:tomdimex((m+1)*(m+1)),y((m+1)*(m+1))x(1)=0y(1)=0n=1t=int(m/2)fori=1totn=n+1x(n)=x(n-1)+1y(n)=y(n-1)dowhiley(n)in=n+1x(n)=x(n-1)y(n)=y(n-1)+1enddodowhilex(n)-in=n+1x(n)=x(n-1)-1y(n)=y(n-1)enddodowhiley(n)-in=n+1x(n)=x(n-1)y(n)=y(n-1)-1enddodowhilex(n)in=n+1x(n)=x(n-1)+1y(n)=y(n-1)enddoendfor?str(m,2)+阶数字方螺线为:fork=1tom*mr=0forj=2tosqrt(k)ifk%j=0r=1exitendifendforifr=0andk#1@25-y(k)*2,80+x(k)*5saystr(k,3)colorGR+/Relse@25-y(k)*2,80+x(k)*5saystr(k,3)endifwaitwindtime0.1endforreturn运行程序,输入M=10,得10阶数字方螺线如下图:1009998979695949392916564636261605958579066373635343332315689673817161514133055886839185431229548769401961211285386704120
本文标题:趣味Visual-FoxPro--程序设计集锦
链接地址:https://www.777doc.com/doc-6129922 .html