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

//第 1 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	char name[40];
	char surname[40];
	printf("Please input your first name:");
	scanf("%s", name);
	printf("Please input your last name:");
	scanf("%s", surname);
	printf("Hello, %s, %s.", name, surname);
	return 0;
}
//第 2 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	char name[40];
	int width;
	printf("Please input your name:") ;
	scanf("%s", name);
	width = printf("\"%s\"\n.", name);
	width -= 4;
	printf("\"%20s\".\n", name);
	return 0;
}
//第 3 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	float input;
	printf("Enter a float number:");
	scanf("%f", &input);
	printf("The input is %.1f or %.1e \n", input, input);
	return 0;
}
//第 4 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	float heigh;
	char name[40];
	printf("Enter your name :");
	scanf("%s", name);
	printf("Hi %s,how tall you are( inch ):", name);
	scanf("%f", &heigh);
	printf("%s,you are %.3f feet tall \n", name, heigh / 12.0);
	return 0;
}
//第 5 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	float speed, size, time;
	printf("Pleast input the net speed (megabits per second):");
	scanf("%f", &speed);
	printf("Pleast input the file size (megabyte):");
	scanf("%f", &size);
	time = size * 8 / speed;
	printf("At %.2f megabits per second, a file of %.2f megabytes download in %.2f seconds.",
		speed, size, time);
	return 0;
}
//第 6 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	char name[40], surname[40];
	int wname, wsurname;
	printf("Please input your first name:");
	scanf("%s", name);
	printf("Please input your last name:");
	scanf("%s", surname);
	wname = printf("%s", name);
	printf(" ");
	wsurname = printf("%s", surname);
	printf("\n%*d %*d", wname, wname, wsurname, wsurname);
	return 0;
}
//第 7 题

#include <stdio.h>
#include <float.h>
int main(void)
{
	double d_third = 1.0 / 3.0;
	float f_third = 1.0 / 3.0;
	printf("float of one third(6) = %.6f\n", f_third);
	printf("float of one third(12) = %.12f\n", f_third);
	printf("float of one third(16) = %.16f\n", f_third);
	printf("double of one third(6) = %.6lf\n", d_third);
	printf("double of one third(12) = %.12lf\n", d_third);
	printf("double of one third(16) = 8.16lf\n", d_third);
	printf("FLT_DIG in float.h is %d\n", FLT_DIG);
	printf("DBL_DIG in float.h is %d\n", DBL_DIG);
	return 0;
}
//第 8 题

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define GALLON_TO_LITRE 3.785
#define MILE_TO_KM 1.609
int main(void)
{
	float range, oil;
	printf("Pleast input the range you traveled(in mile):");
	scanf("%f", &range);
	printf("Pleast input the oil you spend(in gallon):");
	scanf("%f", &oil);
	printf("In UAS, your oil wear is %.1f M/G\n", range / oil);
	printf("In Europe, your oil wear %.1fL/100KM",
		(oil * GALLON_TO_LITRE) / (range * MILE_TO_KM));
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值