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>
int main(){
int a, b, c;
float d;
printf("Input math1, English and math2:");
scanf("%d,%d,%d",&a,&b,&c);
d = (a*5 + b*1.5 + c*3.5) / 10;
printf("Final score = %.2f\n",d);
return 0;
}
2.一尺之捶,日取其半(3分)
题目内容:
我国古代著作《庄子》中记载道:“一尺之捶,日取其半,万世不竭”。其含义是:对于一尺的东西,今天取其一半,明天取其一半的一半,后天再取其一半的一半的一半总有一半留下,所以永远也取不尽。请编写一个程序,使其可以计算出一条长为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>
int main(){
int n;
float m;
printf("Input length and days:");
scanf("%f,%d",&m,&n);
for(;n>0;n--){
m = m / 2;
}
printf("length=%.5f\n",m);
return 0;
}
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>
int main(){
float p,s;
printf("Input payment p:");
scanf("%f",&p);
s = p-p*0.08;
printf("price = %.1f\n",s);
return 0;
}
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
输入提示信息:
“Input time one(hour, minute):”
“Input time two(hour, minute):”
输入格式:“%d,%d”
输出格式:“%d hour %d minute\n”
#include<stdio.h>
int main(){
int h1, h2, m1, m2, h3, m3;
printf("Input time one(hour, minute):");
scanf("%d,%d",&h1,&m1);
printf("Input time two(hour, minute):");
scanf(" %d,%d",&h2,&m2);
if(h1>=h2){
if(m1>=m2){
h3 = h1 - h2;
m3 = m1 - m2;
}else{
h3 = h1 - h2 - 1;
m3 = m1 + 60 - m2;
}
}else{
if(m2>=m1){
h3 = h2 - h1;
m3 = m2 - m1;
}else{
h3 = h2 - h1 - 1;
m3 = m2 + 60 - m1;
}
}
printf("%d hour %d minute\n",h3,m3);
return 0;
}