1.通过实验,观察系统如何处理整数上溢,浮点数上溢和下溢的情况
#include<stdio.h>
int main(void)
{
//整数上溢
int a=2147483647; //32位机器下int的取值范围(-2^31~2^31-1)
printf("整数上溢:%d\n",a+1);
printf("整数上溢:%d\n",a+2);
//浮点数上溢
float toobig=3.4E38*100.0f;
printf("浮点数上溢:%f\n",toobig);
//浮点数下溢
float toolow=1.4E-45;
printf("下溢前:%e\n下溢后:%e\n",toolow,toolow/2);
//浮点数舍入错误
float c,d;
c=2.0e20+1.0;
d=c-2.0e20;
printf("舍入错误:%f",d);
return 0;
}
2.编写一个程序,读取一个浮点数,分别打印成小数点形式,指数形式,p计数法(十六进制计数法)
#include<stdio.h>
int main(void)
{
float x;
scanf("%f",&x);
printf("%f\n",x);
printf("%e\n",x);
printf("%p\n",x);
}