C语言详解(第五版)第二章程序设计项目答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言详解(第五版)程序设计项目答案第二章

1.编写一个程序,以每英里0.35的费率计算一个售货员的里程偿还金。程序中要求与用户进行如下方式的交互。

#include

#include

int main(void)

{float mile_1,mile_2,miles,consume,payment;

printf("MILEAGE REIMBURSEMENT CALCULATOR\n");

printf("Enter begainning odometer reading>\n");

scanf("%f",&mile_1);

printf("Enter endding odometer reading>\n");

scanf("%f",&mile_2);

printf("Enter consume per mile>\n");

scanf("%f",&consume);

miles=mile_2-mile_1;

payment=miles*consume;

printf("You traveled%f miles.At%f per mile,your reimbursement

is%f",miles,consume,payment);

system("pause");

return(0);

}

2.编写一个程序,用于辅助设计水力发电大坝。提示用户输入大坝高度,以及水流量。如果水由重力所做的功有90%转化为电能,测算会有多少M瓦的功率。

#include

#include

int main(void)

{double density,weight,gravitational_acceleration,

efficiency,height,water_flow_rate,work,electricity_power;

printf("Please type in the density of water>");

scanf("%lf",&density);

printf("Please type in the gravitational_acceleration>");

scanf("%lf",&gravitational_acceleration);

printf("Please type in the height of the water>");

scanf("%lf",&height);

printf("Please type in the efficiency of the transformation\nfrom water to electricity>");

scanf("%lf",&efficiency);

printf("Please type in the water_flow_rate>");

scanf("%lf",&water_flow_rate);

weight=density*water_flow_rate;

work=weight*height*gravitational_acceleration;

electricity_power=work*efficiency/1000000;

printf("The electric energy production is%fW",electricity_power);

system("pause");

return0;

}

3.编写一个程序,用于预测冰箱内的温度,断电后经过的时间是给定的。温度公式:。要求程序提示用户输入改时间,它以整数小时和分钟表示。需要注意的是,经历的世间应该转化为小时。

#include

#include

int main(void)

{double time,temperature;

int hour,minute;

printf("Please type in the time,include hour and minute.For example230(2void space 30)>");

scanf("%d%d",&hour,&minute);

time=hour+minute/60;

temperature=time*time*4/(time+2)-20;

printf("The temperature of the refrigerator is%f℃?",temperature);

system("pause");

return0;

}

4.将华氏温度转换成摄氏温度。

#include

#include

int main(void)

{int fahrenheit;

double centigrade;

printf("Please type in temperature in fahrenheit>");

scanf("%d",&fahrenheit);

centigrade=(fahrenheit-32)*5/9;

printf("The temperature%d in fahrenheit equals to the temperature%f in centigrade

",fahrenheit,centigrade);

system("pause");

return0;

}

5.编写一个程序,将两个数作为输入数据,并显示它们的和差积商;

#include

#include

int main(void)

{double x,y;

double sum;

double difference;

double product;

double quotient;

printf("Please type in x and y>");

scanf("%lf%lf",&x,&y);

sum=x+y;

difference=x-y;

product=x*y;

quotient=x/y;

相关文档
最新文档