全国青少年信息竞赛培训教材第一章计算机和计算机语言101【问题描述】求S = 1-2+3-4+……-100102【问题描述】求圆面积程序,写出程序的运行结果。
#include <stdio.h>#include <stdlib.h>char *s = “Let us begin”;int r = 3;double pi = 3.14;main( ){printf(“%s\n”, s);printf(“radium is: %d\n”, r);printf(“Arrea of circle is: %lf\n”, pi * r * r);printf(“Arrea of circle is: %10lf\n”, pi * r * r);printf(“Arrea of circle is: %10.3lf\n”, pi * r * r);// system(“pause”);return 0;}103【问题描述】判定2000-2005年中的每一年是否闰年,输出其中所有闰年的年份。
请写出程序的运行结果。
【源程序】#include <stdio.h>#include <stdlib.h>int year;char leap;main( ){printf("The following are leap years:\n");for (year = 2000; year <= 2500; ++year){leap = 0;if (year % 4 == 0)if (year % 100 != 0) leap = 1;else if (year % 400 == 0) leap = 1;if ( leap ) printf("%d ", year);}// system("pause");return 0;}第二章顺序结构程序设计201【问题描述】鸡和兔子关在一个笼子里,可以看到共有12个头、40只脚,求鸡和兔子各有多少只?【源程序】#include <stdio.h>#include <stdlib.h>main( ){int chick, rabbit;rabbit = (40 - 2 * 12) / 2;chick = 40 - rabbit;printf("%d %d\n", chick, rabbit);// system("pause");return 0;}202【问题描述】已知旅行的距离和汽车平均速度,每公升汽油可以行驶的公里数以及每公升汽油的价格,求驾驶汽车旅游所花费的时间和购买汽油的钱数。
【源程序】#include <stdio.h>#include <stdlib.h>main( ){float s,v,k,p,liter,t,total;printf("请输入s v k p\n");scanf("%f %f %f %f", &s,&v,&k,&p);t = s / v;liter = s / k;total = liter * p;printf("%.2lf %.2lf\n", t,total);// system("pause");return 0;}203【问题描述】笑笑有一些糖果。
第一天,他吃了总数的一半多一颗;第二天,他又吃了剩下糖果的总数的一半多一颗;第三天,他又吃了剩下糖果的总数的一半多一颗。
结果发现,剩下的糖果数量恰好是他的幸运数字。
你能算出笑笑原来一共有多少颗糖果吗?【源程序】#include <stdio.h>#include <stdlib.h>main( ){int n, x;printf("请输入幸运数字:\n");scanf("%d", &n);x = (n + 1) * 2;x = (x + 1) * 2;x = (x + 1) * 2;printf("结果是:\n");printf("%d\n", x);// system("pause");return 0;}204日期写法(date)【问题描述】对于年、月、日的描述,不同国家有不同的描述方式,按年、月、日的方式读入日期,输出中国式的写法(年、月、日),英国式的写法(日/月/年)和美国式的写法(月/日/年)。
输入:从键盘输入正确的年、月、日。
输出:中、英、美式的日期写法。
【源程序】#include <stdio.h>#include <stdlib.h>main( ){int day, month, year;printf("year, month, day = \n");scanf("%d %d %d", &year, &month, &day);printf("Date in PRC form is %d %d %d\n", year, month, day);printf("Date in UK form is %d %d %d\n", day, month, year);printf("Date in USA form is %d %d %d\n", month, day, year);// system("pause");return 0;}205数字分离(splitnum)【问题描述】小明刚学会一位数字的加法运算,小明妈妈想考核小明的运算能力,于是每次给一个四位小数,让小明求各位数字和。
小明妈妈想让你帮她写一个程序,能随机产生一个四位整数,同时给出各位数字和。
这样她能一边做自己的事,一边考核小明。
输入:随机产生一个四位整数。
输出:产生的整数和各位数字和。
【源程序】// splitnum#include <stdio.h>#include <stdlib.h>main( ){int number, a, b, c, d, s;srand( time(NULL) );number = rand( ) % 9000 + 1000; // 随机产生一个四位数a = number % 10; // 下面四行对number数进行拆分b = number / 10 % 10;c = number / 100 % 10;d = number / 1000;s = a + b + c + d;printf("%d\n", number);printf("s = %d\n", s);// system("pause");return 0;}206时间戳(times)【问题描述】国家安全局获得了一份珍贵的材料,上面记载了一个即将进行的恐怖活动的一切。
不过,国家安全局没法得到实施的时间!材料上的时间使用的是LINUX时间戳,即是从1970年1月1日0时0分0秒开始到该时刻总共过了多少秒。
此等重大的责任终于落到你的肩上了,给你该时间戳,你要写个程序计算出恐怖活动在哪一天实施(这里为了简单起见,规定一年12个月,每个月固定为30天)。
输入:一个整数n(0 ≤ n ≤ 2147483647),表示从1970年1月1日0时0分0秒开始到该时刻过了n秒。
输出:一行:三个整数y、m、d,表示恐怖活动在y年m月d日实施。
【源程序】// times#include <stdio.h>#include <stdlib.h>main( ){// 初始化时间int years = 31104000;int months = 2592000;int days = 86400;long n, ys, y, m, d;printf("n = ");scanf("%d", &n);y = n / years;ys = n % years;m = ys / months + 1;ys = ys % months;d = ys / days + 1;printf("%d %d %d\n", 1970+y, m, d);// system("pause");return 0;}207写出下列程序的运行结果#include <stdio.h>main( ){char ch1, ch2, ch3;int i;scanf("%c", &ch1);ch2 = ch1 - 1;ch3 = ch1 + 1;i = ch1;printf("%d %c %c %c\n", i, ch1, ch2, ch3);return 0;}运行后输入:E208写出下列程序的运行结果#include <stdio.h>main( ){int m, x, y, k1, k2;int i, j;scanf("%d %d %d", &m, &i, &j);k1 = 1 << i;k2 = 1 << j;x = m & k1;y = m & k2;printf("%d\n", (x >> i)^(y >> j));return 0;}运行后输入:○1253 1 4 ○2253 4 7209补充完善下列程序#include <stdio.h>#include <math.h>main( ){____ a, b, c, p, s;scanf("%d %d %d", &a, &b, &c);p = (a + b + c) / 2.0;s = ____;printf(____);}提示:使用y=sqrt(x)这个语句可以全y的值为x的平方根。
210编程题(1)从键盘上读入长方形的连长a, b,计算它的面积和周长,输出。
(2)输入:用时、分、秒表示时间长度,把它转换为秒数。
(3)将输入的华氏温度转换为摄氏温度。