欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    C语言题目及答案(共60页).doc

    • 资源ID:15102242       资源大小:182KB        全文页数:61页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C语言题目及答案(共60页).doc

    精选优质文档-倾情为你奉上目录1. Climb the Taishan Mountain(II)2.Peach3.逆序输出数列4.逆序数5.计算高度6.分解质因数7.输出数字8.Problem B:数字之和9.换零钱10.素数求和11.求阶乘和11.Problem F:求一批正整数中的偶数和12.统计各种字符个数13.求最大公约数14.求最大公约数15.零起点学算法101统计字母数字等个数16.网站泄密17.老外买瓷砖18.堆瓷砖19.新年大酬宾20.定制瓷砖21.句子比较大小22.鹦鹉学舌3C语言初学者百题大战之十三23.鹦鹉学舌2C语言初学者百题大战之十二24.百鸡问题25.零起点学算法89程序设计竞赛26.零起点学算法89程序设计竞赛27.Problem A:计算数列和28.找钱问题29.Median30.素月31.输入任意N个数,求和32.多项式求和33.人口问题34.数字菱形专心-专注-专业Climb the Taishan Mountain(II)Time Limit:1000MS Memory Limit:65536KTotal Submit:753 Accepted:495DescriptionLabor day is coming.Since the holiday is long,Many students are planning to have a tour. The Taishan Mountain is very beautiful, so WangPeng and his classmates want to climb the Taishan Mountain. Mountaineering sports is WangPeng's avocation, so he is very excited. Suddenly, a very amusing idea comes to him. The Taishan Mountain has many stairs, and he can climb the mountain one step by 2 stairs or by 1 stairs. How many ways does he have to climb the mountain? For example, the stairs is 2, he has 2 ways.The first one is the first step by 1 stair, and the next step by 1 stair.And the second way is only one step by 2 stairs. InputThe input is including many test cases. Every line is one test case with a integer number N(N<=40). N is the stairs of the Taishan Mountain. OutputYou should output how many ways WangPeng can climb the mountain, each case output a line.Sample Input123Sample Output123#include<stdio.h>int main() int n,i,j,a41; while(scanf("%d",&n)!=EOF) a0=1; a1=2; for(i=2;i<40;i+) ai=ai-1+ai-2; printf("%dn",an-1); PeachTime Limit:1000MS Memory Limit:65536KTotal Submit:689 Accepted:495DescriptionAlmost all young man know Monkey Sun whose name is Sun Wukong. One day he steals many peaches from the kingdom of heaven. First day, he ate a half of the peaches, then ate another one of the left peaches.The next day, he ate a half of the left peaches, then another one.Until the n-th day ,before he ate he found only one peach. Please help Sun Wukong to calculate how many peaches he took from the kingdom of heaven.InputThe input file contains one or more test cases, each line is the days N(1 < n < 30).OutputFor each test case, output a line indicating the number of peaches Monkey Sun had the first day.Sample Input24Sample Output422#include<stdio.h>int main() int n,t,i,s; while(scanf("%d",&n)!=EOF) t=1; s=0; for(i=0;i<n-1;i+) s=(t+1)*2; t=s; printf("%dn",t); 循环练习a+bC语言初学者百题大战之二十二Time Limit:1000MS Memory Limit:65536KTotal Submit:3739 Accepted:2513Description终于到循环结构了。现在开始你可以做很多事情了。 现在我们开始第一个循环题目计算a+b.很多的题目测试数据会有很多组的,一般我们的在线系统没写具体要求的时候,输入是以EOF为结束的。这题的基本框架如下: int main() int a,b; while(scanf("%d%d",&a,&b)!=EOF) /特别注意这行的写法 ./求和 ./输出 scanf函数是有返回值的,如果从键盘上成功读入一个数,那么返回值就是1,如果成功读入2个,则返回2。如果处理到文件末尾,则返回EOF特别注意:题目的要求实际上是指每组数据输入结束后,马上输出这组的结果,而不是等所有数据输完后才输出结果Input输入为多组测试数据。每组一行,每行输入2个整数a和bOutput对于每组测试数据,输出一行,输出a+b的值,直到文件末尾Sample Input2 34 57 8Sample Output5915#include<stdio.h>int main() int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%dn",a+b); 新郎新娘Time Limit:1000MS Memory Limit:65536KTotal Submit:1659 Accepted:1069DescriptionLabor day is long, and many young people will have their wedding between 1st,May and 7th, May. Yesterday, three young couples took photos beside the West Lake. The three bridegroom is A, B, C, and the three bride is X, Y, Z. Mary asked them to know who are the couples.She asked three of them. A said he will marry to X. X said that her young man is C. And C said he will marry to Z. Mary know what all they said is wrong.Since you are very smart, she asks you to help her to find who is the bride of A, who is the bride of B, and who is the bride of C? InputNo Input.OutputOutput three lines. the first line is the bride of A, the second line is the bride of B, the third line is the bride of C.Sample InputSample OutputXYZ(May no the sequence)#include<stdio.h>int main() int x,y,z; for(x=1;x<=3;x+) for(y=1;y<=3;y+) z=6-x-y; if(x!=y&&x!=z&&y!=z&&x!=3&&z!=3&&x!=1) if(x=1) printf("Xn"); if(y=1) printf("Yn"); if(z=1) printf("Zn"); if(x=2) printf("Xn"); if(y=2) printf("Yn"); if(z=2) printf("Zn"); if(x=3) printf("Xn"); if(y=3) printf("Yn"); if(z=3) printf("Zn"); 最大公约数和最小公倍数Time Limit:1000MS Memory Limit:65536KTotal Submit:2745 Accepted:1398DescriptionGiven 2 positive integer x(1<=x<=1000) and y(1<=y<=1000), you are to count the Greatest Common Divisor and the Lease Common Multiple of x and y.Inputthere are multi test cases. x and y, one line for each test.OutputOutput the Greatest Common Divisor and the Lease Common Multiple of x and y in one line for each test.Sample Input12 183 9Sample Output6 363 9Hint学几个单词: Greatest Common Divisor 最大公约数 Lease Common Multiple 最小公倍数 positive integer 正整数 最大公约数可以用辗转相除法 最小公倍数x*y/最大公约数 例题:辗转相除法求gcd(326,78) 326=4×78+14.(78,14) 78=5×14+8.(14,8) 14=1×8+6.(8,6) 8=1×6+2.(6,2) 6=3×2+0.(2,0) 所以gcd(326,78)=2 用while循环来实现 while(y!=0) #include<stdio.h>int main() int x,y,a,b,t,i; while(scanf("%d%d",&x,&y)!=EOF) if(x>y) t=x; x=y; y=t; for(i=x;i>0;i-) if(x%i=0&&y%i=0) a=i; break; b=(x*y)/a; printf("%d %dn",a,b); 查找某一个数Time Limit:1000MS Memory Limit:65536KTotal Submit:1118 Accepted:551Description输入一个从小到大排列的有序数列(长度小于100),在此数列中查找某一个数x,若找到,输出相应下标,否则,输出”Not Found".Input多组测试数据,先输入要查找的数x和n, 再输入n个有序数。Output输出x所在位置下标或"Not Found"Sample Input2 8 -2 2 3 8 9 20 25 675 7 -2 2 3 8 9 20 25 Sample Output1Not Found#include<stdio.h>int main() int n,x,a100,i,s,j; while(scanf("%d",&x)!=EOF) scanf("%d",&n); for(i=0;i<n;i+) scanf("%d",&ai); s=-1; for(j=0;j<n;j+) if(aj=x) printf("%dn",j); s=j; break; if(s=-1) printf("Not Foundn"); 偶数排序Time Limit:1000MS Memory Limit:65536KTotal Submit:630 Accepted:433Description输入一个正整数N和N个整数,将它们中的偶数按从大到小的顺序进行排序后输出。 Input多组测试数据,每组输入一个正整数N(1N100)和N个整数,用空格分隔。 Output将这N个数中的偶数按从大到小的顺序输出Sample Input10 8 4 14 2 11 30 40 500 17 1008 80 200 99 -12 34 55 88 11Sample Output500 100 40 30 14 8 4 2200 88 80 34 -12#include<stdio.h>int main() int n,m,j,q,p,i,b10000,a10000,r,e; while(scanf("%d",&n)!=EOF) for(i=0;i<n;i+) scanf("%d",&bi); e=0; for(r=0;r<n;r+) if(br%2=0) ae=br; e=e+1; m=a0; for(j=0;j<e-1;j+) for(q=j+1;q<e;q+) if(aq>aj) m=aq; aq=aj; aj=m; for(p=0;p<e-1;p+) printf("%d ",ap); printf("%dn",ae-1); N个数从大到小排序Time Limit:1000MS Memory Limit:65536KTotal Submit:1787 Accepted:1254Description输入一个正整数N和N个整数,将它们按从大到小的顺序进行排序后输出。 Input多组测试数据,每组输入一个正整数N(1N100)和N个整数,用空格分隔。 Output将这N个数按从大到小的顺序重新输出。 Sample Input10 -4 5 12 88 23 -9 2 0 8 105 12 3 4 9 -2 Sample Output88 23 12 10 8 5 2 0 -4 -912 9 4 3 -2#include<stdio.h>int main() int n,m,j,q,p,i,a10000; while(scanf("%d",&n)!=EOF) for(i=0;i<n;i+) scanf("%d",&ai); m=a0; for(j=0;j<n-1;j+) for(q=j+1;q<n;q+) if(aq>aj) m=aq; aq=aj; aj=m; for(p=0;p<n-1;p+) printf("%d ",ap); printf("%dn",an-1); N个数从小到大排序Time Limit:1000MS Memory Limit:65536KTotal Submit:2443 Accepted:1289Description输入一个正整数N和N个整数,将它们按从小到大的顺序进行排序后输出。 Input多组测试数据,每组输入一个正整数N(1N100)和N个整数,用空格分隔。 Output将这N个数按从小到大的顺序重新输出 Sample Input10 -4 5 12 88 23 -9 2 0 8 105 12 3 4 9 -2Sample Output-9 -4 0 2 5 8 10 12 23 88-2 3 4 9 12N个数从小到大排序Time Limit:1000MS Memory Limit:65536KTotal Submit:2443 Accepted:1289Description输入一个正整数N和N个整数,将它们按从小到大的顺序进行排序后输出。 Input多组测试数据,每组输入一个正整数N(1N100)和N个整数,用空格分隔。 Output将这N个数按从小到大的顺序重新输出 Sample Input10 -4 5 12 88 23 -9 2 0 8 105 12 3 4 9 -2Sample Output-9 -4 0 2 5 8 10 12 23 88-2 3 4 9 12#include<stdio.h>int main() int n,m,j,q,p,i,a10000; while(scanf("%d",&n)!=EOF) for(i=0;i<n;i+) scanf("%d",&ai); m=a0; for(j=0;j<n-1;j+) for(q=j+1;q<n;q+) if(aq<aj) m=aq; aq=aj; aj=m; for(p=0;p<n-1;p+) printf("%d ",ap); printf("%dn",an-1); 逆序输出数列Time Limit:1000MS Memory Limit:65536KTotal Submit:345 Accepted:282Description输入一个正整数n(n<1<100), 再输入n个整数,按逆序输出这些数。Input多组测试数据,每组输入一个正整数n, 再输入n个整数Output按逆序输出这n个数Sample Input4 3 5 2 88 1 2 3 4 5 6 7 83 88 99 77Sample Output8 2 5 38 7 6 5 4 3 2 177 99 88#include<stdio.h>int main() int n,i,j,a10000; while(scanf("%d",&n)!=EOF) for(i=0;i<n;i+) scanf("%d",&ai); for(j=n-1;j>0;j-) printf("%d ",aj); printf("%dn",a0); 逆序数Time Limit:1000MS Memory Limit:65536KTotal Submit:544 Accepted:365Description输入一个任意整数(int型),输出其位数并逆序输出该数。Input多组测试数据,每组输入一个任意整数(int型)Output输出其位数及逆序数Sample Input12345-123Sample Output54321 5-321 3#include<stdio.h>int main() int n,w,a10000,j,i; while(scanf("%d",&n)!=EOF) w=n; if(n<0) n=-n; for(i=0;i<i+) ai=n%10; if(n=0) break; n=n/10; if(w<0) printf("-"); for(j=0;j<i;j+) printf("%d",aj); printf(" %dn",i); 计算高度Time Limit:1000MS Memory Limit:65536KTotal Submit:519 Accepted:321Description一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第n次落地时,共经过多少米?第n次反弹多高?(输出保留1位小数)Input多组测试数据,每组输入一个整数nOutput第n次落下时在空中经过的路程及第n次反弹的高度Sample Input28Sample Outputdistance=200.0 height=25.0distance=298.4 height=0.4#include<stdio.h>#include<math.h>int main() int n,i; float d,h; while(scanf("%d",&n)!=EOF) h=100.0; d=100.0; for(i=0;i<n;i+) h=h/2*1.0; if(i!=0) d=d+h*4.0; printf("distance="); printf("%.1f ",d); printf("height="); printf("%.1fn",h); 分解质因数Time Limit:1000MS Memory Limit:65536KTotal Submit:205 Accepted:161Description输入一个正整数,分解质因数。例如,输入90,输出90=2*3*3*5。Input多组测试数据,每组输入一个正整数Output输出该数的质因数Sample Input9012Sample Output90=2*3*3*512=2*2*3#include<stdio.h>#include<math.h>int main() int n,t,q,o,i,p,j,a10000,w; while(scanf("%d",&n)!=EOF) w=n; o=0; t=2; if(n=1) printf("1=1n"); if(n!=1) for(i=0;i<i+) if(n%t=0) n=n/t; ao=t; o=o+1; if(n=1) break; if(n%t!=0) for(j=1;j<10000;j+) t=t+1; for(q=2;q<t;q+) if(t%q=0) break; if(q=t) break; printf("%d=",w); for(p=0;p<o-1;p+) printf("%d",ap); printf("*"); printf("%dn",ao-1); 输出数字Time Limit:1000MS Memory Limit:65536KTotal Submit:766 Accepted:320Description输入一个整数,从高位开始逐位分割并输出。例如输入,逐位输出:1,2,3,4,5,6。Input多组测试数据,每组输入一个整数Output逐位输出其各位数字Sample Input-789Sample Output1,2,3,4,5,67,8,9#include<stdio.h>int main() int n,i,a1000,j; while(scanf("%d",&n)!=EOF) if(n<0) n=-n; for(i=0;i<1000;i+) ai=n%10; n=n/10; if(n=0) break; for(j=i;j>0;j-) printf("%d,",aj); printf("%dn",a0); Problem B:数字之和Ti

    注意事项

    本文(C语言题目及答案(共60页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开