C Primer Plus(第6版)第五章编程练习答案

时间:2021-11-25 00:05:44

     第五章编程练习的答案,坚持萌新风格不动摇。

#include<stdio.h>
int main(void)
{
	int Minute, Hour;
	const int SYSTEM = 60;  //定义一个为60的进制用于单位转换
	
	printf("请以分钟为单位输入一个时间:\n");
	scanf("%d", &Minute);
	
	while (Minute >= 0)
	{
		printf("%d分钟等于%d小时%d分钟\n", Minute, Minute / SYSTEM, Minute % SYSTEM );
		printf("请再次以分钟为单位输入一个时间:\n");
		scanf("%d", &Minute);
	}
	printf("输入数据小于等于0,错误。");
	 
	return 0;
	 
 } 
#include<stdio.h>
int main(void)
{
	int x, i;
	i = 0;
	
	printf("请输入一个整数:\n");
	scanf("%d", &x);
	while (i++ < 11)
	{
		printf("%d\t", x++);
	}

	return 0;	 
 } 
#include<stdio.h>
int main(void)  // 符号常量放置在main()函数后
#define SYSTEM 7 //定义一个为7的进制用于单位转换 
{
	int Day;
	
	printf("请以天为单位输入一个时间:\n");
	scanf("%d", &Day);
	
	while (Day >= 0)
	{
		printf("%d天等于%d周%d天\n", Day, Day / SYSTEM, Day % SYSTEM );
		printf("请再次以天为单位输入一个时间:\n");
		scanf("%d", &Day);
	}
	printf("输入数据小于等于0,错误。");
	
	return 0; 
 } 
#include<stdio.h>
int main(void)  
#define SYSTEM 0.3937 //厘米与英寸 
#define SYSTEM1 0.0833  //英寸和英尺 
#define SYSTEM2 0.0328 //厘米和英尺 
{
	float high, n;
	int m;
	
	printf("Enter a height in centimeters:\n");
	scanf("%f", &high);
	
	while (high >= 0)
	{
		m = high * SYSTEM2;
		n = (high * SYSTEM)- (m / SYSTEM1); 
		
		printf("%.1f cm = %d feet, %.1f inches\n", high, m, n);
		printf("Enter a height in centimeters(<=0 to quit):\n");
		scanf("%f", &high);
	}
	printf("bye");
	
	return 0;  
 } 
#include <stdio.h>
int main(void)
{
	int count, sum, day;
	sum = 1;
	count = 1;
	
	scanf("%d", &day);
	
	while (count++ < day)
	 	sum = sum + count;
	printf("sum = %d\n", sum);
	
	return 0;
}
#include <stdio.h>
int main(void)
{
	int count, sum, day, t;
	sum = 0;
	count = 0;
	
	scanf("%d", &day);
	
	while (count++ < day)
	{
		t = count * count; 
		sum = sum + t;
	}
	printf("sum = %d\n", sum);
	
	return 0;
}
#include <stdio.h>
void pound(double n); 
int main(void)
{
	double x;
	
	printf("请输入一个double类型的值:");
	scanf("%lf", &x);
	
	pound(x);
	
	return 0;
}
void pound(double n)
{
	printf("%lf", n * n * n);
}
#include <stdio.h>
int main(void)
{
	int n, m;
	
	printf("This program computes moduli.\n");
	printf("Enter an integer to serve as the second operand:");
	scanf("%d", &n);
	printf("Now Enter the first operand:");
	scanf("%d", &m);
	while (n > 0)
	{
#include <stdio.h> 
void Temperatures(double n);
int main(void)
{
	float n;
	
	while (scanf("%f", &n) == 1) //用于检验返回值,理解为什么只是用一个scanf()函数 
   	{	
		printf("true\n");
		Temperatures(n);	
   	}
	printf("error");
	return 0;
}
void Temperatures(double n)
{
	const float x = 273.16;
	float y = 5.0 / 9.0 * (n -32.0);
	  
	printf("摄氏度:%.2f\n开氏温度:%.2f\n华氏温度:%.2f\n", y, y + x, n);
	
}