C Primer Plus第六版第三章编程练习答案

//观察程序如何处理整数上衣,浮点数上溢和浮点数下溢
#include <stdio.h>
int main(void)
{	
	printf("This is int overflow: %d\n", 2100000000*10000000);
	printf("This is float overflow: %f\n", 9e1000000);
	printf("This is float underflow: %f\n", 0.2e-50);
	
	return 0;
}

程序运行结果
2.

//编写一个程序,提示输入ASCII码,然后打印输入的字符
#include <stdio.h>
int main(void)
{
	char ch;

	printf("\aPlease enter an ASCII Code and the I will get you the correspond character:");
	printf("_\b");
	scanf("%d", &ch);
	printf("%d is the ASCII code for %c. \n", ch);

	return 0;
}
#include <stdio.h>
int main(void)
{	
	printf("\aStartled by the sudden sound, sally shouted,\n");
	printf("\"By the Great Pumpkin, what was that!\"\n");

	return 0;
}

#include <stdio.h>
int main(void)
{
	float f;

	printf("Enter a floating- point value: ");
	scanf("%f", &f);
	printf("fixed-point notation: %f\n", f);  //小数点形式
	printf("exponential notation: %e\n", f);  //指数形式
	printf("p notation: %a\n", f); //p计数法,书上这里运行结果有错

	return 0;
}

//age_sec.c	covert age to second
#include <stdio.h>
int main(void)
{		
	unsigned int age;

	printf("Enter your age: ");
	scanf("%u", &age);
	printf("convert to second is: %f", age * 3.156e7);

	return 0;
}

#include <stdio.h>
int main(void)
{
	double quarts;
	
	printf("Please enter the quarts of water: ");
	scanf("%lf", &quarts);  //注意 获取double类型数据时格式控制应用%lf
	printf("quarts of water contain molecules: %f", (950.0/3.0e-23)*pint); 

	return 0;
}
#include <stdio.h>
int main(void)
{	
	unsigned height;

	printf("Please enter your height in inches: ");
	scanf("%u", &height);
	printf("Your height in centimeters is: %f", height * 2.54);

	return 0;
}
#include <stdio.h>
int main(void)
{
	float cups;
	
	printf("Enter how many the cup of water: ");
	scanf("%f", &cups);
	printf("pint: %f\n", 0.5 * cups);
	printf("ounces: %f\n", 8 * cups);
	printf("Spoon: %f\n", 16 * cups);
	printf("teaspoon: %f\n", 48 * cups);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42912350/article/details/82025452
今日推荐