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

  C语言详解 程序设计项目答案 第二章
  1.编写一个程序,以每英里的费率计算一个售货员的里程偿还金。程序中要求与用户进行如下方式的交互。 #include #include int main(void)
  {float mile_1,mile_2,miles,consume,payment;  printf(\);  printf(\);  scanf(\,&mile_1);  printf(\);  scanf(\,&mile_2);  printf(\);  scanf(\,&consume);  miles=mile_2-mile_1;  payment=miles*consume;  printf(\is %f\,miles,consume,payment); system(\);  return(0); }
  2.编写一个程序,用于辅助设计水力发电大坝。提示用户输入大坝高度,以及水流量。如果水重力所做的功有90%转化为电能,测算会有多少M瓦的功率。 #include  #include  int main(void)
  {double density,weight,gravitational_acceleration,
  efficiency,height,water_flow_rate,work,electricity_power; printf(\); scanf(\,&density);  printf(\); scanf(\,&gravitational_acceleration);  printf(\); scanf(\,&height);  printf(\electricity>\);
  scanf(\,&efficiency);  printf(\); scanf(\,&water_flow_rate);  weight=density*water_flow_rate; 
work=weight*height*gravitational_acceleration;  electricity_power=work*efficiency/1000000;
  printf(\,electricity_power); system(\); return 0; }
  3.编写一个程序,用于预测冰箱内的温度,断电后经过的时间是给定的。温度公式:。要求程序提示用户输入改时间,它以整数小时和分钟表示。需要注意的是,经历的世间应该转化为小时。 #include #include int main(void)
  {  double time,temperature;  int hour,minute;
  printf(\,include hour and  example 2 30(2 void space 30) >\);
  scanf(\,&hour,&minute);  time=hour+minute/60;
  temperature=time*time*4/(time+2)-20;
  printf(\℃\,temperature); system(\); return 0; }
  4.将华氏温度转换成摄氏温度。 #include #include int main(void) {int fahrenheit; double centigrade;
  printf(\);  scanf(\,&fahrenheit); centigrade=(fahrenheit-32)*5/9;
  printf(\\,fahrenheit,centigrade); system(\); return 0; }
  5.编写一个程序,将两个数作为输入数据,并显示它们的和 差 积 商; #include #include in
t main(void) {double x,y; double sum;
  double difference; double product; double quotient;
  printf(\); scanf(\,&x,&y); sum=x+y;
  difference=x-y; product=x*y; quotient=x/y;
  printf(\,sum);
  printf(\,difference); printf(\,product); printf(\,quotient); system(\); return 0; }
  6.如果要使一门课程获得所希望的分数等级没那么预测一下,在期末考试中所需要的分数。编写一个程序实现该目标,程序与用户按如下方式交互: #include #include int main(void) {char rank;
  double minimum_average,current_average,score,percentage; printf(\); scanf(\,&rank);
  printf(\); scanf(\,&minimum_average);
  printf(\); scanf(\,¤t_average);
  printf(\); scanf(\,&percentage);
  score=minimum_average/(percentage/100)-current_average*(100-percentage)/percentage;
  printf(\,score,rank); system(\); return 0; }
  7.编写一个程序,计算在给定燃油的加仑数和房屋内燃油的效率后,可以给房屋释放多少热量。 #include #include int main(void)
  {double volume,energy,efficiency;
  printf(\); scanf(\,&volume);
  printf(\); scanf(\,&efficiency);
  energy=volume/42*5800000*efficiency;
  printf(\,energy); system(\); return 0; }
  9.计算剪草坪的时间 #include #include
  int main(void)
  {double length,width,velocity; double area,time;
  printf(\);  scanf(\,&length,&width); area=length*width;
  printf(\); scanf(\,&velocity); time=area/velocity;
  printf(\,time);  system(\);  return 0; }
  10.编写一个程序,显示两个分数乘积后的分子与分母,并且显示该乘积的百分比。 #includ
e #include int main(void) {double
  numerator1,denominator1,numerator2,denominator2,numerator,denominator,percentage; printf(\);  scanf(\,&numerator1);
  printf(\);  scanf(\,&denominator1);
  printf(\);  scanf(\,&numerator2);
  printf(\);  scanf(\,&denominator2); numerator=numerator1*numerator2;
  denominator=denominator1*denominator2; percentage=numerator/denominator*100;
  printf(\,numerator); printf(\,denominator); printf(\,percentage);  system(\);  return 0; }
  12.勾股三元组的建立 #include #include int main(void)
  {double m,n,side1,side2,hypotenuse; printf(\); scanf(\,&m);
  printf(\); scanf(\,&n); side1=m*m-n*n;
  side2=2*m*n;
  hypotenuse=m*m+n*n;
  printf(\,side1); printf(\,side2);
  printf(\,hypotenuse);  system(\);  return 0; }
c语言程序设计教材答案
  13.编写一个程序,计算喷气式飞机从航空母舰上弹射出发后的加速度。 #include #include int main(void)
  {double acceleration,velocity,velocity_start,distance;;
  printf(\); scanf(\,&velocity_start);
  velocity=velocity_start*1000/3600;
  printf(\); scanf(\,&distance);
  acceleration=2*velocity*velocity/distance;
  printf(\,acceleration);  system(\);  return 0; }
 

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。