600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > MOOC哈工大C语言程序设计精髓编程题测试第五周

MOOC哈工大C语言程序设计精髓编程题测试第五周

时间:2023-09-14 09:31:04

相关推荐

MOOC哈工大C语言程序设计精髓编程题测试第五周

1 马克思手稿中的趣味数学题(4分)

题目内容:

编程求解马克思手稿中的趣味数学题:有30个人,其中有男人、女人和小孩,在一家饭馆里吃饭共花了50先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请编程计算男人、女人和小孩各有几人?

int main(){int man,woman,children;printf("Man Women Children\n");for (int man = 0; man <= 50 / 3; ++man) {for (int woman = 0; woman <= 25; ++woman) {children = 30 - man - woman;if(3 * man + 2 * woman + children == 50){printf("%3d%8d%8d\n",man,woman,children);}}}return 0;}

2 猜神童年龄(4分)

题目内容:

美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是一个4位数。我年龄的4次方是一个6位数。这

10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”请你编程算出他当时到底有多年轻。

int main(){int age,a,b,flag = 1;int data[10];for (int age = 10; age <= 22; ++age) {//三次方a = pow(age,3);//4次方b = pow(age,4);//a为4位数,b为6位数if(a >= 1000 && a <= 9999 && b >= 100000 && b <=999999) {//以10个数作为数组的索引赋值为1for (int i = 0; i < 4; ++i) {data[a % 10] = 1;a = a / 10;}for (int j = 0; j < 6; ++j) {data[b % 10] = 1;b = b / 10;}//如果有一个数组元素不等于1就代表有重复的数字for (int k = 0; k < 10; ++k) {if (data[k] != 1) {flag = 0;break;}}//将数组元素置0for (int l = 0; l < 10; ++l) {data[l] = 0;}if(flag){printf("age=%d\n",age);}}}return 0;}

3 闰年相关的问题v3.0——计算有多少闰年(4分)

题目内容:

从键盘输入你的出生年和今年的年份,编程判断并输出从你的出生年到今年之间中有多少个闰年。

int main(){int birth,year,count = 0;printf("Input your birth year:");scanf("%d",&birth);printf("Input this year:");scanf("%d",&year);for (int i = birth; i <= year; i++) {if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0){printf("%d\n",i);count++;}}printf("count=%d\n",count);return 0;}

4 闰年相关的问题v4.0——计算心跳数(4分)

题目内容:

假设人的心率为每分钟跳75下,编程从键盘输入你的出生年和今年的年份,然后以年为单位计算并输出从你出生开始到目前为止的生命中已有的心跳总数(要求考虑闰年)。

int main(){unsigned int birth,year,count = 0;printf("Input your birth year:");scanf("%d",&birth);printf("Input this year:");scanf("%d",&year);for (int i = birth; i < year; ++i) {//是闰年多加1天的心跳数if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0){count += 75 * 60 * 24;}count += 75 * 60 * 24 * 365;}printf("The heart beats in your life: %lu",count);return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。