C Primer Plus第六版第三章答案

省略第一第二题,迟一点在另一篇博文里补上答案。
这次会在题目前面写上一些难点考点。

Btw这一章对新手不友好啊,看完了一遍感觉似懂非懂,之后继续学的时候需要再回过头来学一次。

第三题:
*printf(“”)里如果还需要有双引号,需要用"来表示。

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	printf("\a Startled by the sudden sound, Sally shouted,\n\"By the Great Pumpkin, what was that!\""); 
	return 0;
} 
//在printf里面要打印用到双引号的话,要在双引号前面加\ 

第四题:
注意不同的输出格式,小数%f,指数%e

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	float value;
	printf("Enter a floating-point value: ");
	scanf("%f",&value);
	printf("fixed-point notation: %f",value);
	printf("\n");
	printf("exponential notation: %e",value);
	return 0;
}

第五题:

int main(int argc, char *argv[]) {
	int age;
	double second;
	
	printf("Please enter your age: ");
	scanf("%d",&age);
	second=age*3.156e7;
	printf("You have been in the world for %f seconds!",second);
	return 0;
}

第六题
注意要预测数据输出的格式,如果是指数的话要用%e

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	double number;
	double answer;

	printf("Please enter your katos: ");
	scanf("%f",&number);
	answer=950*number/3.0e-23;
	printf("You got %e atoms in total!",answer);  //注意此处%e! 
	return 0;
}

第七题:

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	float inch;
	float centimeter;
	
	printf("Please enter your height in inches: ");
	scanf("%f",&inch);
	centimeter=inch*2.54;
	printf("Your height in centimeters is: %f",centimeter);
	
	return 0;
}

第八题
这道题懒得查体积单位的英文名了,直接用了拼音/拼音加s

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	float cup,pintuo,pansi,tangshao,chashao;
	
	printf("Please enter the amount of cups: ");
	scanf("%f",&cup);
	pintuo=cup/2;
	pansi=cup*8;
	tangshao=pansi*2;
	chashao=tangshao*3;
	printf("%f cups equals to %f pintuos, %f pansis, %f tangshaos, %f chashaos.",cup,pintuo,pansi,tangshao,chashao);
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值