我是靠谱客的博主 天真红牛,最近开发中收集的这篇文章主要介绍C Primer Plus (第6版)中文版 第四章答案,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

答案都是自己撰写,仅供参考

4.8.1

#include <stdio.h>
int main(void)
{
char first_name[10];
char last_name[10];
printf("Please enter your first name and last name: ");
scanf_s(" %s %s", first_name,10, last_name,10);
//加数字限定读取长度,不然可能报错
printf("Your name is : %s,%sn", first_name, last_name);
return 0;
}

4.8.2

#include <stdio.h>
int main(void)
{
char name[20];
int length;
printf("Please enter your name: ");
scanf_s(" %s", name, 20);
printf("a."%s"n", name);
printf("b."%20s"n", name);
printf("c."%-20s"n", name);
length = strlen(name);
printf("d."%*s"n", length + 3, name);
return 0;
}

4.8.3

#include <stdio.h>
int main(void)
{
float a;
printf("enter a number:");
scanf_s("%f", &a);
printf("The input is %.1f or %.1e.n", a, a);
return 0;
}

4.8.4

#include <stdio.h>
int main(void)
{
float height;
printf("enter your height(cm):");
scanf_s("%f", &height);
printf("Dabney,you are %.2f m.n", height / 100);
return 0;
}

4.8.5

#include <stdio.h>
int main(void)
{
float speed;
float size;
float time;
printf("Please enter the speed(Mb/s): ");
scanf_s(" %f", &speed);
printf("Please enter the file size(MB): ");
scanf_s(" %f", &size);
time = size * 8 / speed;
printf("At %.2f megabiits per second,
a file of %.2f megabytes downloads in %.2f seconds.n", speed, size, time);
return 0;
}

4.8.6

#include <stdio.h>
int main(void)
{
char first_name[10];
char last_name[10];
int size1, size2;
printf("Please enter your first name: ");
scanf_s(" %s", first_name, 10);
printf("Please enternyour last name: ");
scanf_s(" %s", last_name, 10);
size1 = strlen(first_name);
size2 = strlen(last_name);
printf("%s %sn", first_name, last_name);
printf("%*d %*dn", size1, size1, size2, size2);
printf("%s %sn", first_name, last_name);
printf("%-*d %-*dn", size1, size1, size2, size2);
return 0;
}

4.8.7

#include <stdio.h>
#include <float.h>
int main(void)
{
double a = 1.0 / 3.0;
float b = 1.0 / 3.0;
printf("FLT_DIG: %dnDBL_DIG: %dn", FLT_DIG, DBL_DIG);
printf("float: %.6f %.12f %.16fn", b,b,b);
printf("double: %.6f %.12f %.16fn", a, a, a);
return 0;
}

4.8.8

#include <stdio.h>
int main(void)
{
const float GALLON_TO_LITRE = 3.785;
const float MILE_TO_KM = 1.609;
float distance;
float gasoline_comsume;
printf("enter the distance(mile): ");
scanf_s(" %f", &distance);
printf("enter the gasoline comsume(gallon): ");
scanf_s(" %f", &gasoline_comsume);
printf("In Europe,your oil wear is %.1flitre/100km.n",
(gasoline_comsume * GALLON_TO_LITRE) / (distance * MILE_TO_KM / 100));
printf("In USA,your oil wear is %.1fmile/gallon.n", distance / gasoline_comsume);
return 0;
}

记录学习过程,若有错误或者更好的方案,欢迎大佬留言交流!
//如果觉得不错,不妨留个赞

最后

以上就是天真红牛为你收集整理的C Primer Plus (第6版)中文版 第四章答案的全部内容,希望文章能够帮你解决C Primer Plus (第6版)中文版 第四章答案所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部