1学分绩计算(3分)
题目内容:
已知某大学期末考试学分绩的计算公式为:学分绩 =(工科数学 * 5 + 英语 * 1.5 + 线性代数 * 3.5) / 10
请编程从键盘按顺序输入某学生的工科数学、英语和线性代数成绩,计算并输出其学分绩。
以下为程序的运行结果示例:
Input math1, English and math2:80,70,100↙
Final score = 85.50
输入提示信息:“Input math1, English and math2:”
输入格式: “%d,%d,%d”
输出格式:“Final score = %.2f\n”
#include <stdio.h> #include <stdlib.h> int main() {
int a,b,c; float score; printf("Input math1, English and math2:"); scanf( "%d,%d,%d",&a,&b,&c); score = (a*5+b*1.5+c*3.5)/10; printf("Final score = %.2f\n",score);// }
讯享网
我国古代著作《庄子》中记载道:“一尺之捶,日取其半,万世不竭”。其含义是:对于一尺的东西,今天取其一半,明天取其一半的一半,后天再取其一半的一半的一半总有一半留下,所以永远也取不尽。请编写一个程序,使其可以计算出一条长为m的绳子,在n天之后剩下的长度。
运行结果示例1:
Input length and days:12,5↙
length=0.37500
运行结果示例2:
Input length and days:57.6,7↙
length=0.45000
输入提示信息:“Input length and days:”
输入格式: “%f,%d”
输出格式:“length=%.5f\n”
讯享网#include <stdio.h> #include <stdlib.h> int main() {
int a; float b; printf("Input length and days:"); scanf( "%f,%d",&b,&a); for (int i=0;i<a;i++){
b=b/2; } printf("length=%.5f\n",b); }
3网购打折商品V1.0(4分)
题目内容:
某网上购物网站对用户实行优惠,买家购物货款p越多,则折扣越多。今天正值该网站优惠折扣日,买家可以获得8%的折扣。请编程从键盘输入买家购物货款p,计算并输出买家折扣后实际应付出的价钱。
注:程序中的数据类型为float。
程序的运行结果示例1:
Input payment p:300↙
price = 276.0
程序的运行结果示例2:
Input payment p:1299.8↙
price = 1195.8
输入提示信息:“Input payment p:”
输入格式: “%f”
输出格式:“price = %.1f\n” (注:等号左右均有空格)
#include <stdio.h> #include <stdlib.h> int main() {
float b; printf("Input payment p:"); scanf( "%f",&b); b*=(1-0.08); printf("price = %.1f\n",b);// }
4计算时间差V1.0(4分)
题目内容:
编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。要求不输出时间差的负号。
程序的运行结果示例1:
Input time one(hour, minute):4,55↙
Input time two(hour, minute):1,25↙
3 hour 30 minute
程序的运行结果示例2:
Input time one(hour, minute):1,56↙
Input time two(hour, minute):3,25↙
1 hour 29 minute
输入格式:“%d,%d”
输出格式:“%d hour %d minute\n”
讯享网#include <stdio.h> #include <stdlib.h> #include <math.h> int main() {
int m1,m2,h1,h2,t1,t2,t3; printf("Input time one(hour, minute):"); scanf( "%d,%d",&h1,&m1); printf("Input time two(hour, minute):"); scanf( "%d,%d",&h2,&m2); t1 = h1*60+m1; t2 = h2*60+m2; t3 = abs(t1-t2); printf("%d hour %d minute\n",t3/60,t3%60); }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/27690.html