C Primer Plus--第3章 数据和C

3.11 编程练习

/*习题1:查看当前系统整数的上限和下限*/
#include<stdio.h>
#include<limits.h>  //INT_MAX,INT_MIN
#include<float.h>

int main(void) 
{
	int i = 2147483647;
	float a = 3.402823e38 * 100.0f;
	float b = -1.175494e-38 / 100.0f;
	printf("%d,%d,%d\n",i,i+1,i+2);
	
//	printf("%d,%d\n",INT_MAX,INT_MIN);
    
//  printf("%e,%e\n",FLT_MAX,FLT_MIN);

    printf("%e\n",a);
    printf("%e\n",b);
	
	return 0;
}
2147483647,-2147483648,-2147483647
1.#INF00e+000
-1.175493e-040
--------------------------------
Process exited after 0.03005 seconds with return value 0
请按任意键继续. . .
/*习题2:编写一个程序,要求输入一个ASCII码值,然后输出相应的字符*/
#include<stdio.h>

int main(void)
{
	int ascii;
	printf("Please enter an ASCII code:\n");
	scanf("%d",&ascii);
	printf("%d is  the ASCII code for %c.\n",ascii,ascii);
	
	return 0;
}
Please enter an ASCII code:
65
65 is  the ASCII code for A.
--------------------------------
Process exited after 1.949 seconds with return value 0
请按任意键继续. . .
/*习题3:编写一个程序,发出警报声,并打印下列文字“Stareled by the sudden sound, sally shouted, “By the Great Pukin,what was that!” ”*/

#include<stdio.h>

int main(void)
{
	
	printf("\a");
	printf("Stareled by the sudden sound, sally shouted,");
	printf("\" By the Great Pukin,what was that! \"\n");
	
	return 0;
 } 
Stareled by the sudden sound, sally shouted," By the Great Pukin,what was that! "
--------------------------------
Process exited after 0.03047 seconds with return value 0
请按任意键继续. . .
/*习题4:编写一个程序,读入一个浮点数,并分别以小数形式和指数形式打印。*/
#include<stdio.h>

int main(void)
{
	float num; 
	
    printf("Please enter a float number:");
	scanf("%f",&num);
	printf("Float style: %f exp seyle: %e\n",num,num);

	return 0;
 } 
Please enter a float number:21.29
Float style: 21.290001 exp seyle: 2.129000e+001
--------------------------------
Process exited after 6.786 seconds with return value 0
请按任意键继续. . .
/习题5:*一年约有3.156*10^7s,编写一个程序,要求输入您的年龄,然后显示该年龄合多少秒。*/ 
#include<stdio.h>

int main(void)
{
	int age;
	float second;
	printf("请输入您的年龄:"); 
	scanf("%d",&age); 
	second = 3.156e7*age; 
	printf("您来到地球已经 %f 秒.\n",second); 

	return 0;
 } 
请输入您的年龄:24
您来到地球已经 757440000.000000.
--------------------------------
Process exited after 2.964 seconds with return value 0
请按任意键继续. . .
/*习题6:一个水分子的质量约3.0*10^-23g,1夸脱水大约有950g。编写一个程序,要求输入水的夸脱数,然后显示这么多水中包含多少个水分子。*/
#include<stdio.h>

int main(void)
{
	float mass = 3.0e-23;
	float mass_quart = 950;
	float quarts;
	
	printf("Please enter the number of quart: ");
	scanf("%f",&quarts);
	printf("%f quarts of warter contain  %e of molucules.\n",quarts,quarts*mass_quart/mass); 
	
	return 0;
 } 
Please enter the number of quart: 10.2
10.200000 quarts of warter contain  3.230000e+026 of molucules.
--------------------------------
Process exited after 2.718 seconds with return value 0
请按任意键继续. . .
/*习题7:1英寸等于2.54cm。编写一个程序,以厘米单位输入您的身高,然后显示该身高值等于多少英寸。*/
#include<stdio.h>

int main(void)
{
	float cm;
	printf("Please enter your height in (cm):");
	scanf("%f",&cm); 
	printf("Your height in inch is %f.\n",cm/2.54); 
	
	return 0;
 } 
Please enter your height in (cm)177
Your height in inch is 69.685039 .
--------------------------------
Process exited after 2.141 seconds with return value 0
请按任意键继续. . .
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值