C语言程序填空练习题(二).docx

上传人:夺命阿水 文档编号:1407573 上传时间:2024-06-15 格式:DOCX 页数:8 大小:22.66KB
返回 下载 相关 举报
C语言程序填空练习题(二).docx_第1页
第1页 / 共8页
C语言程序填空练习题(二).docx_第2页
第2页 / 共8页
C语言程序填空练习题(二).docx_第3页
第3页 / 共8页
C语言程序填空练习题(二).docx_第4页
第4页 / 共8页
C语言程序填空练习题(二).docx_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《C语言程序填空练习题(二).docx》由会员分享,可在线阅读,更多相关《C语言程序填空练习题(二).docx(8页珍藏版)》请在课桌文档上搜索。

1、将下面的程序补充完整,以完成指定的功能。1 .尼科彻斯定理ThisprogramistoverifyTheoremofNicoqish.Thatisthecubeofanyintegercanberepresentedasthesumofsomecontinueoddnumbers.Forexample,83=512=57+59+61+63+65+67+69+71.includeusingnamespacestd;intmain()(intn,a,i;while(1)(coutn;if(n=O);/(D/输出等差数列,首项为a*a-a+1,公差为2,项数为na=n*n-n+1;coutn,*,

2、n*n,=n*n*n=,a;for(i=1;i+)/(2)cout+,;/(3)coutendl;)returnO;)2 .角谷猜想ThisprogramistoverifyJiaoguGuess.Thatisgivenanynaturalnumber,ifitisaneven,divides2,ifitisanodd,multiple3andadd1,theresultcontinuestobecalculatedanalogously.Aftersometimes,theresultisalways1.#includeusingnamespacestd;intmain()(intn,a,i

3、,cnt;while(1)(coutn;if(n=O)break;/(1)cnt=O;coutResultsofverification:n;doif(/(2)n=n*3+1;cout,StepNo.+cnt,(n-1)3*3+1=nendl;)else(n=2;coutStepNo.+cnt2*n72=nendl;)while();/(3)coutendl;)return0;)3 .四方定理ThisprogramistoverifyTheoremofFourSquares.Thatisallnaturalnumberscanberepresentedassumofnomorethan4squ

4、aresofthenumbers.e.g.,123=7*7+7*7+4*4+3*3.#includeusingnamespacestd;intmain()(inti,j,kJ,number;while(1)coutnumber;if(number=O);/(1)coutResultsofverification:n;for(i=1;i=number/2;i+)for0=O;j=i;j+)for(k=0;k=j;k+)for(l=0;l=k;l+)if()/(2)(coutnumber=i*i,+j*j+k*,k+l*endl;gotoexit;)exit:coutn;returnO;)4 .亲

5、密数Thisisaprogramtofindfriendlynumberspair.WhichmeansthesumofintegerAsallfactors(exceptA)equalstothesumofintegerBsallfactors(exceptB)#includeusingnamespacestd;intmain()(inta,i,b,n,m;coutn;coutnTherearefollowingfriendly-numberspairsmallerthannendl;for(a=1;an;a+)(for(;i=a/2;i+)/(1)if(!(a%i)b+=i;for(;i=

6、b/2;i+)/(2)if(!(b%i)m+=i;if(&ab)/(3)couta.,bm;)coutendl;return0;)5 .自守数Thisprogramwillfindtheautomorphicnumbers.Thedefinationofaautomorphicnumberis:themantissaofanaturalnumberssquareequalstoitself.e.g.,52=25,762=5776,93762=87909376.#includeusingnamespacestd;intmain()(intmul,number,k,kk;for(number=0;

7、number1OOOOjnumber+)(for(mul=number,k=1;k*=10);/(1)kk=k*10;mul=number*number%kk;if()/(2)coutnumber)coutendl;return0;)6 .特殊的四位数Thisprogramwillfindthefourfigureswhichhavethecharacteristicasfollows:abcd=(ab+cd)2.e.g.,3025=(30+25)*(30+25).#includeusingnamespacestd;intmain()intn,a,b;for(n=1000;n10000;n+)

8、(;/(1);/(2)if(a+b)*(a+b)=n)coutn,;)coutendl;return0;)7 .求方程COS(X)x=0的根Thisprogramistofindtherealrootoffunctioncos(x)-x=0.includeincludeusingnamespacestd;intmain()float0,x1=0.0;while(1)(; /(1); /(2)if(fabs(x-x1)1e-6)break;)coutTherealrootis,x1endl;return0;)8 .特殊的3位数ThisprogramistofindthePerfectSquare

9、Numbers.whichhave3digits,and2ofthemarethesame,e.g.100,121,144,225,400,441,484,676,900.include#includeusingnamespacestd;intmain()(inti,n,a,b,c;for(i=10;i=sqrt(1000);i+)(;/(1)a=n100;/(2)c=n%10;if(a=bHa=cb=c)coutn;)coutendl;return0;)9 .三重回文数ThisprogramistofindthePalindromeNumbers,whosesquareandcubicare

10、alsoPalindromeNumbers.includeusingnamespacestd;boolisPalindrome(intn)(intx,y=0;x=n;while(x!=0)(;/(1);/(2)returny=n;)intmain()(intm;for(m=11;m1000;m+)(if(isPalindrome(m)&isPalindrome(m*m)&isPalindrome(m*m*m)coutmm*mMm*m*mendl;)returnO;10 .SIXandNINEThisprogramistofindthenumbersofSIXandNINE,whichsatis

11、fytheformulaSIX+SIX+SIX=NINE+NINE,whereS,I,X,N,Estandfordigitsbetween0and9.#includeusingnamespacestd;intmain()inti,x,a,b,c,d;for(i=668;i=999;)/(1)(x=3*i2;a=i10%10;b=x100%10;c=x1000;d=x%10010;if()/(2)(coutixendl;)return0;)或includeusingnamespacestd;intmain()(ints,i,x,n,e,six,nine;for(s=1;s10;s+)for(i=

12、0;i10;i+)for(x=0;x10;x+)for(n=1;n10;n+)for(e=0;e10;e+)(six=;/(3)nine=;/(4)if()/(5)coutsix,nineendl;)return0;)11 .马克思手稿中的数学题ThisprogramistosolveaninterestingmathquestioninKarlMarxsmanuscript.TheProblemisasfollows:30personsspent50yuaninarestaurant,amonythem,eachmanspent3yuan,eachwomanspent2yuan,andeac

13、hchildspent1yuan.Thequestionishowmanymen,womenandchildrenarethere?#includeusingnamespacestd;intmain()(intx,y,z;coutMentWomentChildren,endl;for(x=0;x=10;x+)(;/(1);/(2)if()/(3)coutxty,t,zendl;)return0;)12 .百钱百鸡问题ThisprogramistosolveProblemofHundredYuanHundredFowls.WhichispresentedbyZhangQiujiang,aChin

14、eseancientmathematician,inhisworkBibleofCalculation:5Yuancanbuy1cock,3Yuancanbuy1hen,1Yuanbuy3chickens,nowonehas100Yuantobuy100fowls,thequestionishowmanycocks,hens,chickenstobuy?includeusingnamespacestd;intmain()(intx,y,z;for(x=0;x+)H外层循环控制鸡翁数x(1)for(y=0;y+)内层循环控制鸡母数y(2)(z=100-x-y;if()/(3)coutcock=x

15、,hen=y,chicken=,zendl;)return0;13 .三色球问题ThisprogramistosolveProblemofThreeColorBaI1.TheProblemisasfollows:Thereare12ballsinthepocket.Amonythem,3ballsarered,3ballsarewhiteand6ballsareblack.Nowtakeoutany8ballsfromthepocket,howmanycolorcombinationsarethere?#includeusingnamespacestd;intmain()(inti,j,cnt

16、=O;coutREDtWHITEtB1.ACK,endl;for(i=0;i+)/(1)for(j=0;j+)/(2)if()/(3)cout+cntH:,itj,t,8-i-jendlreturn0;)14 .配对新郎和新娘ThisprogramistosolveProblemofBridegroomandBride.TheProblemisasfollows:Someonegoesto3coupleslovers,wedding.ThebridegroomsareA,B,CandthebridesareX,YZ.Hewantstoknowwhomarrieswhoandasksthem.A

17、sayshewillmarrytoX,XsaysherfianceisC,CsaysheW川marrytoZ.Themanknowsthattheyareallkidding.Whattheysaidisnottrue.Sotrytofindwhowillmarrytowho?#includeusingnamespacestd;intmain()(intx,y,z;for(x=1;x=3;x+)/穷举x的全部可能配偶for(y=1;y=3;y+)/穷举y的全部可能配偶for(z=1;z=3;z+)/穷举Z的全部可能配偶if(x!=1&x!=3&z!=3&x!=y&x!=z&y!=z)cout*

18、Xwillmarryto,char()endl;H(1)cout*Ywillmarryto,char()endl;H(1)coutZwillmarryto,char()endl;H(1)return0;)15 .邮票组合ThisprogramistosolveProblemofStampCombination-TheProblemisasfollows.Johnhas4stampswithvalueof3centsand3stampswithvalueof5cents.Useoneormoreofthesestamps,howmanykindsofpostagescanJohnprovide?

19、includeusingnamespacestd;intmain()(inti,j,s,=0,a28=0;for(i=0;i=4;i+)for(j=0;j=3;j+)(;/(1)if()as=1;n+;/(2)coutThereare,n-1kindsofpostages:nM;for(i=1;i=27;i+)if()couti11;/(3)coutendl;returnO;参考答案:1.(1)break(2)i0(2)number=mul6.(1)a=n100(2)b=n%1007.(1)x=x1(2)x1=cos(xO)8.(1)n=i*i(2)b=n10%109.(1)y=y*10+x%10(2)x=x1010.(1)i=i+2(2)a=b&c=d(3)s*100+i*10+(4)n*1000+i*100+n*10+e(5)3*six=2*nine11.12.(1)y=20-2*x(2)z=30-x-y(3)3*x+2*y+z=50(1)x=20(2)y=33(3)z%3=0&5*x+3*y+z/3=1OO13. (1)i=3(2)j=3(3)(8-i-j)=614. (1),A,+x-1(2),A+y-1(3),A+z-115. (1)s=i*3+j*5(2)as=O(3)ai=1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号