/*6.编写一个程序,设置一个值为 1.0/3.0 的 double 类型变量和一个值为 1.0/3.0 的 float 类型变
量。每个变量的值显示三次:一次在小数点右侧显示 4 个数字,一次在小数点右侧显示 12 个数字,另一次
在小数点右侧显示 16 个数字。同时要让程序包括 float.h 文件,并显示 FLT—DIG 和 DBL_DIG 的值。 1.0/3.0
的显示值与这些值一致吗?*/
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
int main()
{
double a = 1.0 / 3.0;
float b = 1.0 / 3.0;
printf("%.4f\n", a);
printf("%.12f\n", a);
printf("%.16f\n\n", a);
printf("%.4f\n", b);
printf("%.12f\n", b);
printf("%.16f\n\n", b);
printf("FLT_DIG and DBL_DIG:%d and %d\n", FLT_DIG, DBL_DIG);
system("pause");
return 0;
}
C Primer Plus4-6
最新推荐文章于 2022-01-18 20:44:29 发布