《国家计算机二级编程题.docx》由会员分享,可在线阅读,更多相关《国家计算机二级编程题.docx(64页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、湖南省一级程序设计题库过程及答案1编程序求出1-200以内的能被7整除的数的平方和。377986cleas=0m=0for i= 1 to 200ifi%7=0m=iA2s=s+mendifendfor?s2编程序求卜99的平方根的和并输出结果。(保留小数点两位)661.46cleas=0for i=l to 99s=s+sqrt(i)endfor?round(s,2)3编程序求155的平方根的和并输出结果。(保留小数点两位) 275.43cleas=0for i=l to 55s=s+sqrt(i)endfor?round(s,2)4编程序统计11000能被3整除的数的个数。333cleas
2、=0for n=l to 1000ifn%3=0s=s+lendifendfor?s7编程序求出1到5000之间的能被5整除的前若干个偶数之和,当和大于500时程序退出。550cleas=0for n= 10 to 5000 step 10s=s+nifs500exitendifendfor ?s8编程序求在3000以内被17或者23整除的正整数数的个数。299 cleas=0for n=l to 3000if n% 17=0 or n%23=0s=s+lendifendfor ?s9序求在1000以内被17或者23整除的正整数数的个数。99cleas=0for n=l to 1000if n
3、% 17=0 or n%23=0s=s+lendifendfor?s10编程序求在5000以内被17或者23整除的正整数数的个数。499clea for n=l to 5000if n% 17=0 orn%23=0s=s+lendifendfor?s11编程序求出1-100以内的能被3整除的数的平方和。112761cleas=0for n=l to 100ifn%3=0s=s+nA2endifendfor?s12已知一个数列的前3个数为0, 0, 1,以后每个数为前3个数的和,编程序求此数列的第36个数。334745777cleadime f(36)f(D=of(2)=0f(3)=ls=0fo
4、r n=4 to 36f(n)=f(n-3)+f(n-2)+f(n-l)s=f(n)endfor?s13编程序求出1-100以内的能被9整除的数的平方和。40986cleas=0for n=l to 100ifn%9=0s=s+nA2endifendfor?s14编程序求出1-200以内的能被3整除的数的平方和。882189cleas=0for n=l to 200if n%3=0s=s+nA2endifendfor?s15编程序求出1-7000以内能被3或者7整除数的个数。3000cleas=0for n=l to 7000if n%3=0 or n%7=0s=s+lendifendfor?
5、s16 序求出l3000以内能被3或者5整除数的个数。1400cleas=0for n= 1 to 3000if n%3=0 or n%5=0s=s+lendifendfor?s17编程序求出1-5000以内能被3或者7整除数的个数。2142cleas=0for n= 1 to 5000ifn%3=0or n%7=0s=s+lendifendfor?s18编程序求出1-6000以内能被3或者5整除数的个数。2800cleas=0for n=l to 6000if n%3=0 or n%5=0s=s+lendifendfor?s19编程序求出l4000以内能被3或者11整除数的个数。1575cl
6、eas=0for n=l to 4000ifn%3=0 or n%ll=0s=s+1endifendfor?s20编程序求出1-5000以内能被37整除的整数之和。339660cleas=0for n= 1 to 5000if n%37=0s=s+nendifEndfor?s21编程序求出1-6000以内能被23整除的整数之和。780390cleas=0for n=l to 6000ifn%23=0s=s+nendifendfor22编程序求出13000以内能被33整除的整数之和。135135cleas=0for n=l to 3000 ifn%33=0s=s+nendifendfor?s23
7、编程序求出1-5000以内能被15整除的整数之和。834165clea s=0 for n=l to 5000 if n% 15=0 s=s+nendifendfor?s24编程序求出100到200之间同时满足除3余2和除5余3条件的数的个数。6cleas=0for n=100to 200ifn%3=2 and n%5=3s=s+lendifendfor?s25编程序求出1到300之间同时满足除3余2和除5余3条件的数的个数。20cleas=0for n=l to 300if n%3=2 and n%5=3s=s+lendifendfor?s26编程序求出100到500之间同时满足除3余2和除
8、5余3条件的数的个数。26cleas=0for n= 100 to 500ifn%3=2 and n%5=3s=s+lendif endfor?s27编程序求出1到400之间同时满足除3余2和除5余3条件的数的个数。27cleas=0for n= Ito 400ifn%3=2 and n%5=3s=s+lendifendfor?s28编程序求出100到600之间同时满足除3余2和除5余3条件的数的个数。33cleas=0for n=100 to 600ifn%3=2 and n%5=3s=s+lendifendfor?s29编程序求出1到500之间同时满足除3余2和除5余3条件的数的个数。33
9、cleas=0for n=lto 500if n%3=2 and n%5=3s=s+lendifendfor?s30 1编程序求出2+4+8+16+32+这样的数之和。如果累加数大于500时,则程序终止并输出结果。510cleas=0for n=l to 100s=s+2Anifs500exitendifendfor?s31编程序求出1100所有整数的立方和并输出结果。25502500cleas=0for n=1 to 100 s=s+nA3endfor ?s32编程序求出1 110所有整数的立方和并输出结果。37271025cleas=0for n=1 to 110s=s+nA3endfor
10、 ?s33编程序求出1 66所有整数的立方和并输出结果。4888521cleas=0for n=1 to 66s=s+nA3endfor ?s34编程序求出1 150所有整数的立方和并输出结果。128255625cleas=0for n=1 to 150s=s+nA3endfor ?s35编程序求出1180所有整数的立方和并输出结果。265364100cleas=0for n=1 to 180s=s+nA3endfor ?s36编程序求出1 200所有整数的立方和并输出结果。404010000cleas=0for n=1 to 200s=s+nA3endfor ?s37编程序求出1 21。所有
11、整数的立方和并输出结果。490844025cleas=0for n=1 to 210 s=s+nA3endfor ?s38编程序求出S=1130所有整数的立方和并输出结果。72505225clea s=0for n=1 to 130 s=s+nA3endfor ?s39编写程序,计算1000以内有多少个这样的数,该数既能被6整除又能被8整除。 41clea s=0for n=1 to 1000if n%6=0 and n%8=0s=s+1 endifendfor ?s40编程序求1110所有整数的平方和并输出结果。449735clea s=0for n=1 to 110s=s+nA2endfo
12、r ?s 41编程序求1120所有整数的平方和并输出结果。583220cleas=0for n=1 to 120s=s+nA2endfor ?s 42编程序求180所有整数的平方和并输出结果。173880clea s=0 for n=1 to 80s=s+nA2endfor ?s43编程序求1150所有整数的平方和并输出结果。1136275clea s=0for n=1 to 150s=s+nA2endfor?s44编程序求160所有整数的平方和并输出结果。73810cleas=0for n=1 to 60s=s+nA2endfor?s45编程序求190所有整数的平方和并输出结果。247065
13、cleas=0for n=1 to 90s=s+nA2endfor?s46编程序求1108所有整数的平方和并输出结果。425754cleas=0for n=1 to 108s=s+nA2endfor?s47编程序求1145所有整数的平方和并输出结果。1026745cleas=0for n=1 to 145s=s+nA2endfor?s48编程序求1250所有整数的平方和并输出结果。5239625cleas=0for n=1 to 250s=s+nA2endfor?s49编程序求1300所有整数的平方和并输出结果。9045050cleas=0for n=1 to 300s=s+nA2endfor
14、?s50编程序求出1到5000之间的能被7整除的前若干个数之和,当和大于1500时退出并输出结果。1617cleas=0for n=1 to 5000if n%7=0s=s+nendifif s1500exitendifendfor?s51编程序求出1到3000之间的能被3整除的前若干个数之和,当和大于600时退出并输出结果。630cleas=0for n=1 to 3000if n%3=0s=s+nendifif s600exitendifendfor?s52编程序求出1到2000之间的能被9整除的前若干个数之和,当和大于500时退出并输出结果。594cleas=0for n=1 to 20
15、00if n%9=0s=s+nendifif s500exitendifendfor?s53编程序求出1到6000之间的能被5整除的前若干个偶数之和,当和大于650时退出并输出结果。660cleas=0for n=1 to 6000if n%5=0 and n%2=0s=s+nendifif s650exitendifendfor?s54编程序求出1到7000之间的能被5整除的前若干个偶数之和,当和大于500时退出并输出结果。550cleas=0for n=1 to 7000if n%5=0 and n%2=0s=s+nendifif s500exitendifendfor?s55编程序求出1
16、到4000之间的能被5整除的前若干个偶数之和,当和大于400时退出并输出结果。450cleas=0for n=1 to 4000if n%5=0 and n%2=0s=s+nendifif s400exitendifendfor?s56编程序求出1到8000之间的能被5整除的前若干个偶数之和,当和大于750时退出并输出结果。780cleas=0for n=1 to 8000if n%5=0 and n%2=0s=s+nendif if s750exitendifendfor?s57编程序统计1200能被3整除的个数。66cleas=0for n=1 to 200if n%3=0s=s+1end
17、ifendfor?s58编程序统计1300能被3整除的个数。100cleas=0for n=1 to 300if n%3=0s=s+1endifendfor?s59编程序统计200400能被3整除的个数。67cleas=0for n=200 to 400if n%3=0s=s+1endifendfor?s60编程序统计150300能被3整除的个数。51cleas=0for n=150 to 300if n%3=0s=s+1endifendfor?s61编程序统计150400能被3整除的个数。84cleas=0for n=150 to 400if n%3=0s=s+1endifendfor?s6
18、2编程序统计100500能被3整除的个数。133cleas=0for n=100 to 500if n%3=0s=s+1endifendfor?s63编程序统计200600能被3整除的个数。134cleas=0for n=200 to 600if n%3=0s=s+1endifendfor?s64编程序统计200300能被3整除的个数。34cleas=0for n=200 to 300if n%3=0s=s+1endifendfor?s65编程序统计300500能被3整除的个数。67cleas=0for n=300 to 500if n%3=0s=s+1endifendfor?s66编程序求1
19、65的平方根的和并输出结果。(保留小数点两位)353.19cleas=0for n=1 to 65s=s+sqrt(n)endfor?round(s,2)67编程序求166的平方根的和并输出结果。(保留小数点两位)361.32cleas=0for n=1 to 66s=s+sqrt(n)endfor?round(s,2)68编程序求185的平方根和并输出结果。(保留小数点两位)526.85cleas=0for n=1 to 85s=s+sqrt(n)endfor?round(s,2)69编程序求195的平方根的和并输出结果。(保留小数点两位)621.97cleas=0for n=1 to 95
20、s=s+sqrt(n)endfor?round(s,2)70编程序求1125的平方根的和并输出结果。(保留小数点两位)937.08cleas=0for n=1 to 125s=s+sqrt(n)endfor?round(s,2)71编程序求1135的平方根的和并输出结果。(保留小数点两位)1051.31cleas=0for n=1 to 135s=s+sqrt(n)endfor?round(s,2)72编程序求1155的平方根的和并输出结果。(保留小数点两位)1292.51cleas=0for n=1 to 155s=s+sqrt(n)endfor?round(s,2)73编程序求1115的平
21、方根的和并输出结果。(保留小数点两位)827.32cleas=0for n=1 to 115s=s+sqrt(n)endfor?round(s,2)74编程序求178的平方根的和并输出结果。(保留小数点两位)463.46cleas=0for n=1 to 78s=s+sqrt(n)endfor?round(s,2)75已知一个数列的前3个数为0, 1, 2,以后每个数为前3个数的和,编程序求此数列的第30个数。24548655cleadime f(30)f(1)=0f(2)=1f(3)=2s=0for n=4 to 30f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor
22、?s76已知一个数列的前3个数为0, 1, 1,以后每个数为前3个数的和,编程序求 此数列的第20个数。35890cleadime f(20)f(1)=0f(2)=1f(3)=1s=0for n=4 to 20f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s77已知一个数列的前3个数为0, 1, 2,以后每个数为前3个数的和,编程序求此数列的第25个数。 1166220cleadime f(25)f=0f(2)=1f(3)=2s=0for n=4 to 25f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s78已知一个数列的前3个数为1
23、, 2, 3,以后每个数为前3个数的和,编程序求此数列的第20个数。101902cleadime f(20)f=1f(2)=2f(3)=3s=0for n=4 to 20f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s79已知一个数列的前3个数为0, 1, 2,以后每个数为前3个数的和,编程序求此数列的第35个数。516743378cleadime f(35)f(1)=0f(2)=1f(3)=2s=0for n=4 to 35f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s80已知一个数列的前3个数为1, 2, 3,以后每个数为前3个
24、数的和,编程序求此数列的第35个数。950439251cleadime f(35)f(1)=1f=2f(3)=3s=0for n=4 to 35f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s81已知一个数列的前3个数为3, 4, 5,以后每个数为前3个数的和,编程序求此数列的第28个数。25527448cleadime f(28)f=3f(2)=4f(3)=5s=0for n=4 to 28f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s82已知一个数列的前3个数为3, 4, 5,以后每个数为前3个数的和,编程序求此数列的第33个数
25、。537346739cleadime f(33)f(1)=3f(2)=4f(3)=5s=0for n=4 to 33f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s83已知一个数列的前3个数为3, 4, 5,以后每个数为前3个数的和,编程序求此数列的第26个数。7545856cleadime f(26)f(1)=3f(2)=4f(3)=5s=0for n=4 to 26f(n)=f(n-3)+f(n-2)+f(n-1)s=f(n)endfor?s84编程序求2+4+8+16+32+这样的数之和。如果累加数大于1500时,则程序 终止并输出结果。2046cleas=
26、0for n=1 to 100q=2Ans=s+qif s1500exitendifendfor?s85编程序求2+4+8+16+32+这样的数之和。如果累加数大于980时,则程序终止并输出结果。1022cleas=0for n=1 to 100q=2Ans=s+qif s980exitendifendfor?s86编程序求2+4+8+16+32+这样的数之和。如果累加数大于3000时,则程序终止并输出结果。4094cleas=0for n=1 to 100q=2Ans=s+qif s3000exitendifendfor?s87编程序求2+4+8+16+32+.这样的数之和。如果累加数大于5
27、000时,则程序终止并输出结果。8190cleas=0for n=1 to 100q=2Ans=s+qif s5000exitendifendfor?s88编程序求1+3+5+7+9+这样的数之和。如果累加数大于750时,则程序终止并输出结果。784cleas=0for n=1 to 800 step 2s=s+nif s750exitendifendfor?s89编程序求1+3+5+7+9+这样的数之和。如果累加数大于1200时,则程序终止并输出结果。1225cleas=0for n=1 to 800 step 2s=s+nif s1200exitendifendfor?s90编程序求2+4
28、+8+16+32+这样的数之和。如果累加数大于9000时,则程序终止并输出结果。16382cleas=0for n=1 to 100q=2Ans=s+qif s9000exitendifendfor?s91编程序求1+3+5+7+9+这样的数之和。如果累加数大于1300时,则程序终止并输出结果。1369cleas=0for n=1 to 800 step 2s=s+nif s1300exitendifendfor?s92编程序求1+3+5+7+9+这样的数之和。如果累加数大于900时,则程序终止 并输出结果。961cleas=0for n=1 to 800 step 2s=s+nif s900
29、exitendifendfor?s93编程序求1+3+5+7+9+这样的数之和。如果累加数大于1000时,则程序终止并输出结果。1024cleas=0for n=1 to 800 step 2s=s+nif s1000exitendifendfor?s94编程序求1100能被7整除的个数。14cleas=0for n=1 to 100if n%7=0s=s+1endifendfor?s95编程序求1600能被11整除的个数。54cleas=0for n=1 to 600if n%11=0s=s+1endifendfor?s96编程序求11000能被15整除的个数。66cleas=0for n=
30、1 to 1000if n%15=0s=s+1endifendfor?s97编程序求1800能被5整除的个数。160cleas=0for n=1 to 800if n%5=0s=s+1endifendfor?s98编写程序,求1, 1000既能被6整除又能被7整除的数的个数。2cleas=0for n=1 to 100if n%6=0 and n%7=0s=s+1endifendfor?s99编写程序,求1, 500既能被3整除又能被5整除的数的个数。33cleas=0for n=1 to 500if n%3=0 and n%5=0s=s+1endifendfor?s100编写程序,求1,50
31、0既能被6整除又能被7整除的数之和。2772cleas=0for n=1 to 500if n%6=0 and n%7=0s=s+nendif endfor ?s101已知24有8个正整数因子(即:1,2,3,4,6,8,12,24),而24正好被其因子个数8整除。求1,100之间第10个能被其因子数目整除的正整数。56cleas=0q=0for n=1 to 100m=0for j=1 to nif n%j=Om=m+1endifnextif n%m=0s=s+1q=nif s9 &当它大于9时,q已经是第十个数了! exitendifendifendfor?q102求666,777范围内素
32、数的个数。16cleas=0for n=666 to 777q=0for j=2 to sqrt(n) if n%j=Oq=1endifnextif q=0s=s+1endifendfor?s103求351,432之间所有既不能被3整除,又不能被8整除的正整数的个数。47cleas=0for n=351 to 432if n%3!=0 and n%8!=0 s=s+1endif endfor?s104求444,666范围内最大的素数是多少?661cleas=0for n=444 to 666q=0for j=2 to sqrt(n) if n%j=Oq=1 endifnextif q=0 s=
33、nendifendfor ?s105有一个分数序列:2/1,3/2,5/3,8/5,13/8,21/13.(注:该数列从第二项开始,其分子是前一项的分子与分母的和,而其分母是前一项的分子),求出这个序列 前24项的和。要求:按四舍五入的方式精确到小数点后第二位。39.13cleas=0k=0m=2n=1for j=1 to 24 k=m/ns=s+k y=m m=m+nn=y endfor?round(s,2)106已知24有8个正整数因子(即:1,2,3,4,6,8,12,24),而24正好被其因子个数8整除。问100,300之间有多少个能被其因子数目整除的数。19cleas=0q=0for
34、 n=100 to 300m=0for j=1 to nif n%j=Om=m+1endifnextif n%m=Os=s+1endifendfor?s107 求1, 5000之间能同时被3和7整除的数的个数。238cleas=0for n=1 to 5000if n%3=0 and n%7=0s=s+1endifendfor?s108设某国今年的国民生产总值为45600亿元,若今后每年以8%的增长率增长,计算多少年后能实现国民生产总值翻两番?192008cleas=0dime f(1000)f(1 )=45600f(2)=49248f(3)=53187.84q=2&从第二年开始计算年份,所以
35、f(1)不算。for n=4 to 1000f(n)=f(n-1)*1.08s=f(n)q=q+1if s=182400exitendifendfor?q109求1, 5000之间能被3或7整除的数的个数。2142cleas=0for n=1 to 5000if n%3=0 or n%7=0s=s+1endifendfor?s110已知24有8个因子(即:1, 2, 3, 4, 6, 8, 12, 24),而24正好被8整除。求1,100之间第二大能被其因子数目整除的数。88cleas=0q=0for n=100 to 1 step -1m=0for j=1 to nif n%j=Om=m+1
36、endifnextif n%m=0s=s+1q=nif s1 &当它大于1时,q已经是第2个数了!exitendifendifendfor?q111 若某整数平方等于某两个正整数平方之和的正整数称为弦数。例如:由 于3A2+4八2=5八2,贝屿为弦数,求100, 200之间最大的弦数。 200 cleas=100q=0for n=100 to 200for j=1 to n-1for k=1 to n-1if kA2+jA2=nA2q=n if qss=qendifendifendforendforendfor?s112 若某整数N的所有因子之和等于N的倍数,则N称为多因子完备数,如 数28,
37、其因子之和1+2+4+7+14+28=56=2*28,28是多因子完备数。求1,500之间 有多少个多因子完备数。5cleas=0for n=1 to 500m=0for j=1 to nif n%j=0 m=m+j endifnextif m%n=0s=s+1 endif endfor ?s113若某整数N的所有因子之和等于N的倍数,则N称为多因子完备数,如数28,其因子之和1+2+4+7+14+28=56=2*28,28是多因子完备数。求1,200之间 有多少个多因子完备数。4 cleas=0for n=1 to 200m=0for j=1 to nif n%j=0 m=m+j endif
38、nextif m%n=0s=s+1 endif endfor ?s114设某国今年的国民生产总值为45600亿元,若今后每年以9%的增长率增长,计算多少年后能实现国民生产总值翻一番? 9cleas=0dime f(1000) f(1 )=45600 f(2)=45600*1.09 f(3)=(45600*1.09)*1.09q=2&从第二年开始计算年份,所以f(1)不算。for n=4 to 1000*n)=f(n.1)T.O8s=f(n)q=q+iif s=45600*2 exitendifendfor?q115已知24有8个正整数因子(即4,6,8,12,24),而24正好被其因子个数8整
39、除。求100,300之间能被其因子数目整除的数中最大的数。296cleas=0q=0for n=100 to 300m=0for j=1 to nif n%j=Om=m+1endifnextif n%m=0s=s+1q=nendifendfor?q116有一个三位数满足下列条件:(1)此三位数的三位数字各不相同;(2)此三位数等于它的各位数字的立方和。试求这种三位数共有多少个?4cleas=0for n=100 to 999a=int(n/100)b=int(n/10)%10c=n%10if aA3+bA3+cA3=n and a!=b and b!=c and c!=as=s+1endife
40、ndfor?s117找满足以下条件:XA2+YA2+ZA2=4M2且X+Y+Z之值最大的三个正整数X,Y,Z,求X+Y+Z之值. 71cleas=0for x=1 to 41for y=1 to 41for z=1 to 41if xA2+yA2+zA2=41A2 k=x+y+z if ks s=k endifendif endfor endfor endfor ?s118求2, 500之间的所有素数的和。21536cleas=0for n=2 to 500q=0for j=2 to sqrt(n) if n%j=O q=i endifnext if q=0 s=s+n endifendfor
41、 ?s119求31000之间最大的五个素数之和。4919cleas=0 q=0 for n=1000 to 3 step -1 m=0for j=2 to sqrt(n) if n%j=Om=1 endif next if m=0 s=s+n q=q+1if q4 exit endif endifendfor?s120有一个分数序列:2/1,3/2,5/3,8/5,13/8,21/13.(即:该数列从第二项开始,其分子是前一项的分子与分母之和,而其分母是前一项的分子),求出这个序列前 56项的和。要求:按四舍五入的方式精确到小数点后第三位。90.909cleas=0 k=0 m=2n=1for j=1 to 56 k=m/ns=s+k y=m m=m+n n=y endfor?round(s,3)121已知24有8个因子(即:123,4,6,8,12,24),而24正好被8整除。求100,300之间所有能被其因子数目整除的数之和。3769cleas=0for n=100 to 300m=0for j=1 to n if n%j=O m=m+1