1. 程式人生 > >C Primer Plus(第6版)第五章程式設計練習答案

C Primer Plus(第6版)第五章程式設計練習答案

     第五章程式設計練習的答案,堅持萌新風格不動搖。

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