为了按科学记数法打印数字,必须在printf()函数中使用"%e"格式说明符,例如:
float f=123456.78;
printf("%e is in scientific/n",(float)i);
当然,如果要对整数进行这样的处理,则必须先把它转换为浮点数:
int i=10000;
printf("%e is in scientific/n",f);
下面的程序演示了格式说明符“%e”的作用:
- #inclued <stdio. h>
- main ( )
- {
- double f = 1.0 / 1000000. O;
- int i ;
- for(i = O; i< 14; ++ i )
- {
- printf( " %f = %e\n" , f , f );
- f *= 10.0;
- }
- return( 0 );
- }