价格优惠的C语言程序,c语言程序设计精髓第三章编程题

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"

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:32000kb

程序:

#includeint 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分)

题目内容:

我国古代著作《庄子》中记载道:“一尺之捶,日取其半,万世不竭”。其含义是:对于一尺的东西,今天取其一半,明天取其一半的一半,后天再取其一半的一半的一半总有一半留下,所以永远也取不尽。请编写一个程序,使其可以计算出一条长为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"

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:32000kb

程序:

#includeint 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,计算并输出买家折扣后实际应付出的价钱。

注:程序中的数据类型为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" (注:等号左右均有空格)

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:31kb

程序:

#includeint 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分)

题目内容:

编程从键盘任意输入两个时间(例如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"

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:32000kb

程序1:

#include#includeint 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;

}

程序2:

#include#includemain()

{

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值