在dev-c++5.7.1中,程序如下:
#include <stdio.h>
int main(void)
{
float a=9876543210123456789.0;
double b=9876543210123456789.0,d;
long double c=9876543210123456789.0;
d=(double)c;
printf("float is %2dB\n",sizeof(float));
printf("double is %2dB\n",sizeof(double));
printf("long double is %2dB\n",sizeof(long double));
printf("float a = %30.10f\n",a);
printf("double b = %30.10lf\n",b);
printf("long double c = %30.10Lf\n",c);
printf("double d = c = %30.10Lf\n",d);
}
运行结果为:
float is 4B
double is 8B
long dlouble is 12B
float a=9876543516404875300.0000000000
double b=9876543210123456500.0000000000
long dlouble c= -0.0000000000
double d = c = 9876543210123456500.0000000000
从结果和其它尝试可知:
(1)long dlouble 是12字节的浮点数,存储的数据正确,但是用printf()函数无法输出?
(2)尝试过用%lg、%le等格式均不能正确输出。
(3)此程序在VC++6.0中运行正常,但是VC++6.0中long dlouble是8字节长的,实际为double型数据,不能回答本问题。
试问:用printf() 如何输出12字节的 long double 类型数据?
#include <stdio.h>
int main(void)
{
float a=9876543210123456789.0;
double b=9876543210123456789.0,d;
long double c=9876543210123456789.0;
d=(double)c;
printf("float is %2dB\n",sizeof(float));
printf("double is %2dB\n",sizeof(double));
printf("long double is %2dB\n",sizeof(long double));
printf("float a = %30.10f\n",a);
printf("double b = %30.10lf\n",b);
printf("long double c = %30.10Lf\n",c);
printf("double d = c = %30.10Lf\n",d);
}
运行结果为:
float is 4B
double is 8B
long dlouble is 12B
float a=9876543516404875300.0000000000
double b=9876543210123456500.0000000000
long dlouble c= -0.0000000000
double d = c = 9876543210123456500.0000000000
从结果和其它尝试可知:
(1)long dlouble 是12字节的浮点数,存储的数据正确,但是用printf()函数无法输出?
(2)尝试过用%lg、%le等格式均不能正确输出。
(3)此程序在VC++6.0中运行正常,但是VC++6.0中long dlouble是8字节长的,实际为double型数据,不能回答本问题。
试问:用printf() 如何输出12字节的 long double 类型数据?