C primer plus (第6版)中文版 第五章答案

//第 1 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define MIN_PER_HOU 60
int main(int argc, char* argv[])
{
	int hours, minutes, input;
	printf("CONVERT MINUTES TO HOURS!\n");
	printf("PLEASE INPUT THE NUBER OF MINUTES( <=0 TO QUIT ):");
	scanf("%d", &input);
	while (input > 0)
	{
		hours = input / MIN_PER_HOU;
		minutes = input % MIN_PER_HOU;
		printf("CONVERT TO %d HOUR AND %d MINUTES\n", hours, minutes);
		printf("PLEASE CONTINUE INPUT THE NUMBER OF MINUTES( <=0 TO QUIT ):");
		scanf("%d", &input);
	}
	printf("PROGRAM EXIT!\n");
}
//第 2 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(int argc, char* argv[])
{
	int counter, i = 0;
	printf("PRINT COUNTINUE 10 NUMBERS!\n");
	printf("PLEASE INPUT THE START NUMBER :");
	scanf("%d", &counter);
	while (i++ < 11)
	{
		printf(" %d \n", counter++);
	}
	printf("PROGRAM EXIT!\n");
	return 0;
}
//第 3 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define WEEK_PER_DAY 7 
int main(int argc, char* argv[])
{
	int days, weeks, input;
	printf("CONVERT DAYS TO WEEKS!\n");
	printf("PLEASE INPUT THE NUMBER OF DAYS( <=0 TO QUIT ):");
	scanf("%d", &input);
	while (input > 0)
	{
		weeks = input / WEEK_PER_DAY;
		days = input % WEEK_PER_DAY;
		printf("%d days are %d weeks, %d days\n", input, weeks, days);
		printf("PLEASE INPUT THE NUMBER OF DAYS( <=0 TO QUIT ) :");
		scanf("%d", &input);
	}
	printf("PROGRAM EXIT! \n");
	return 0;
}
//第 4 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define FEET_TO_CM 30.48
#define INCH_TO_CM 2.54
int main(int argc, char* argv[])
{
	int feet;
	float inches, cm;
	printf("CONVERT CM TO INCHES!\n");
	printf("Enter the height in centimeters:");
	scanf("%f", &cm);
	while (cm > 0)
	{
		feet = cm / FEET_TO_CM;
		inches = (cm - feet * FEET_TO_CM) / INCH_TO_CM;
		printf("%.1f cm = %d feet,%.1f inches\n", cm, feet, inches);
		printf("Enter the height in centimeters( <= 0 TO QUIT ):");
		scanf("%f", &cm);
	}
	printf("PROGRAM EXIT! \n"); 
	return 0;
}
//第 5 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(int argc, char* argv[])
{
	int count = 0, sum = 0;
	printf("Enter the number of days you work:");
	scanf("%d", &count);
	while (count > 0)
	{
		sum = sum + count--;
	}
	printf("You earned $ %d total!\n", sum);
	printf("PROGRAM EXIT!\n");
	return 0;
}
//第 6 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(int argc, char* argv[])
{
	int count = 0, sum = 0;
	printf("Enter the number of days you work:");
	scanf("&d", &count);
	while (count > 0)
	{
		sum = sum + count * count;
		count--;
	}
	printf("You earned $ %d total!\n", sum);
	printf("PROGRAM EXIT! \n");
	return 0;
}
//第 7 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
double cubic(double n);
int main(int argc, char* argv[])
{
	double input;
	printf("Enter the double datum to calc cubic :");
	scanf("%lf", &input);
	cubic(input);
	printf("PROGRAM EXIT!\n");
	return 0;
}
double cubic(double n)
{
	double t = n * n * n;
	printf("The %lg's cubic is %lg !\n", n, t);;
	return t;
}
//第 8 题

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(int argc, char* argv[])
{
	int first, second;
	printf("This program computes moduli.\n");
	printf("Enter an integer to server as the second operand:");
	scanf("%d", &second);
	printf("Now enter the first operand:");
	scanf("%d", &first);
	while (first > 0)
	{
		printf("%d %% %d is %d\n", first, second, (first % second));

		printf("Enter next number for first operand( < 0 to quit):");
		scanf("%d", &first);
	}
	printf("Done!\n");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值