C语言题目及答案(共60页).doc
《C语言题目及答案(共60页).doc》由会员分享,可在线阅读,更多相关《C语言题目及答案(共60页).doc(61页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上目录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.零起点学算法8
2、9程序设计竞赛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
3、. The Taishan Mountain is very beautiful, so WangPeng and his classmates want to climb the Taishan Mountain. Mountaineering sports is WangPengs 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 b
4、y 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 i
5、s 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#includeint main() int n,i,j,a41; while(scanf(%d,&n)!=EOF) a0=1; a1=2; for(i=2;i40;i+)
6、 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 o
7、f 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 th
8、e 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#includeint main() int n,t,i,s; while(scanf(%d,&n)!=EOF) t=1; s=0; for(i=0;in-1;i+) s=(t+1)*2; t=s; printf(%dn,t); 循环练习a+bC语言初学者百题大战之二十二Time Limit:1000
9、MS 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。如果处理到文件末尾,则返回
10、EOF特别注意:题目的要求实际上是指每组数据输入结束后,马上输出这组的结果,而不是等所有数据输完后才输出结果Input输入为多组测试数据。每组一行,每行输入2个整数a和bOutput对于每组测试数据,输出一行,输出a+b的值,直到文件末尾Sample Input2 34 57 8Sample Output5915#includeint main() int a,b; while(scanf(%d%d,&a,&b)!=EOF) printf(%dn,a+b); 新郎新娘Time Limit:1000MS Memory Limit:65536KTotal Submit:1659 Accepted:
11、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
12、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 thre
13、e 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)#includeint 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(
14、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
15、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学几个单词: G
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 题目 答案 60
限制150内