# c语言程序设计精髓第三章编程题

83 篇文章 34 订阅

1 学分绩计算（3分）

Input math1, English and math2:80,70,100↙

Final score = 85.50

#include<stdio.h>
int main()
{
double score;
int m1, e, m2;
printf("Input math1, English and math2:");
scanf("%d,%d,%d",&m1,&e,&m2);
score = (m1*5 + e*1.5 + m2*3.5) / 10;
printf("Final score = %.2f\n",score);

return 0;
}

### 2 一尺之捶，日取其半（3分）

Input length and days:12,5↙

length=0.37500

Input length and days:57.6,7↙

length=0.45000

#include<stdio.h>
int main()
{
float length;
int days,i;
printf("Input length and days:");
scanf("%f,%d",&length,&days);
for( i=1; i<=days; i++ )
{
length=length/2;
}
printf("length=%.5f\n",length);

return 0;
}

### 3 网购打折商品V1.0（4分）

某网上购物网站对用户实行优惠，买家购物货款p越多，则折扣越多。今天正值该网站优惠折扣日，买家可以获得8%的折扣。请编程从键盘输入买家购物货款p，计算并输出买家折扣后实际应付出的价钱。

Input payment p:300↙

price = 276.0

Input payment p:1299.8↙

price = 1195.8

#include<stdio.h>
int main()
{
float price;
printf("Input payment p:");
scanf("%f",&price);
price = price * 0.92;
printf("price = %.1f\n",price);

return 0;
}

### 4 计算时间差V1.0（4分）

Input time one(hour, minute):4,55↙

Input time two(hour, minute):1,25↙

3 hour 30 minute

Input time one(hour, minute):1,56↙

Input time two(hour, minute):3,25↙

1 hour 29 minute

"Input time two(hour, minute):"


#include<stdio.h>
#include<math.h>
int main()
{
int hour1, minute1;
int hour2, minute2;
printf("Input time one(hour, minute):");
scanf("%d,%d",&hour1, &minute1);
printf("Input time two(hour, minute):");
scanf("%d,%d",&hour2, &minute2);

int ih = abs(hour2 - hour1);
int im = minute2 - minute1;
if(im < 0){
im = 60 +im;
ih--;
}
printf("%d hour %d minute\n",ih, im);
return 0;
}

#include<stdio.h>
#include<math.h>
main()
{
typedef struct clock
{
int hour;
int minute;
int second;
} CLOCK;
struct clock stu1;
struct clock stu2;
struct clock stu3;
printf("Input time one(hour, minute):");
scanf("%d,%d", &stu1.hour,&stu1.minute);
printf( "Input time two(hour, minute):");
scanf("%d,%d", &stu2.hour, &stu2.minute);
stu3.hour = fabs((stu1.hour * 60 + stu1.minute) - (stu2.hour * 60 + stu2.minute)) / 60;
stu3.minute = fabs(((stu1.hour * 60 + stu1.minute) - (stu2.hour * 60 + stu2.minute)) % 60);

printf("%d hour %d minute\n", stu3.hour, stu3.minute);

}

03-27 1802
02-19 2862
10-11 4117
03-17 5519

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

suxiaorui

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。