C Primer Plus(第六版)第五章 编程练习答案
Posted 水番正文
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C Primer Plus(第六版)第五章 编程练习答案相关的知识,希望对你有一定的参考价值。
前言:由于不是太复杂,第五章的程序我就全部集成在一个程序了,仅供参考,新手勿喷。
(梅开三度
CH05 Code answer:
#include<stdio.h>
#define SIXTY 60
const float YINCUN = 0.5;
const float YINCHI = 0.3;
void double_printf(double x);
void Temperatures(double t);
int main(void)
{
printf("5.11.1\\n");
float min1=1;
while(min1 > 0)
{
printf("请输入分钟单位的时间:");
scanf("%f",&min1);
printf("现在为 %2.0f分钟 %f小时\\n",min1,min1/SIXTY);
}
printf("\\n");
printf("5.11.2\\n");
int num1,test;
printf("请输入一个整数:");
scanf("%d",&num1);
test = num1;
while(num1++ <= test+10)
{
printf("num1:%d \\t\\n",num1-1);
}
printf("\\n");
printf("5.11.3\\n");
int day=1;
int week,days;
printf("请输入天数");
while(day > 0)
{
scanf("%d",&day);
week = day / 7;
days = day % 7;
printf("%d day are %d weeks,%d days\\n",day,week,days);
}
printf("\\n");
printf("5.11.4\\n");
float height;
printf("Enter a height in centimeters:");
while(1 == scanf("%f",&height),height > 0) //加个条件要>0,就可以实现非正数退出
{
printf("%f cm = %f feet, %f inches\\n",height,height*YINCHI,height*YINCUN);
printf("Enter a height in centimeters (<=0 to quit)");
}
printf("bye\\n");
printf("\\n");
printf("5.11.5\\n");
int count1=0,sum1=0,num2;
printf("输入一个数,计算到此数的和:");
scanf("%d",&num2);
while(count1++<num2)
{
sum1 += count1;
}
printf("和为:%d\\n",sum1);
printf("\\n");
printf("5.11.6\\n");
int count2=0,sum2=0,num3;
printf("输入一个数,计算到此数的平方和:");
scanf("%d",&num3);
while(count2++<num3)
{
sum2 += count2*count2;
}
printf("平方和为:%d\\n",sum2);
printf("\\n");
printf("5.11.7\\n");
double d_n;
printf("请输入一个double类型的数:"); //输入的是 lf !!!!
scanf("%lf",&d_n);
double_printf(d_n); //这边只用传参不用声明
printf("\\n");
printf("5.11.8\\n");
int op1,op2;
printf("This program computes moduli.\\n");
printf("Enter an integer to serve as the second operand:");
scanf("%d",&op2);
printf("Now enter the first operand:");
while(1 == scanf("%d",&op1) , op1 > 0)
{
printf("%d %% %d is %d\\n",op1,op2,op1%op2);
printf("Enter next number for first operand (<= 0 to quit):");
}
printf("Done\\n");
printf("\\n");
printf("5.11.9\\n");
double h;
printf("请输入一个华氏温度:");
while(1 == scanf("%lf",&h))
{
Temperatures(h);
printf("请继续输入一个华氏温度(如果想退出输入任意非数字):");
}
printf("结束");
printf("\\n");
}
void double_printf(double x) //返回值类型 函数名 函数定义
{
printf("立方为:%f\\n",x*x*x);
}
void Temperatures(double t)
{
const float HUASHI = -32*5/9;
const float KAISHI = 273.16;
printf("华氏:%lf\\n摄氏:%lf\\n开氏:%lf\\n",t,t*5/9+HUASHI,t+KAISHI);
}
以上是关于C Primer Plus(第六版)第五章 编程练习答案的主要内容,如果未能解决你的问题,请参考以下文章