C: printing double using printf
Posted by Joys of Programming on in C/C++
If you want to use large floating numbers in C, you can use double instead of float. Printing a double is shown here
#include <stdio.h>
int main()
{
/*Floating point number - double*/
double fvar = 25.01;
/*Printing size of a double*/
printf ("Size of double %i bytes\n", sizeof(fvar));
/*Printing double*/
printf ("%lf\n", fvar);
printf ("%g\n", fvar);
/*Printing double*/
printf ("%e\n", fvar);
return 0;
}
The output of this program
Size of double 8 bytes 25.010000 25.01 2.501000e+01
The size of a double is 8 bytes. There are three ways by which we printed the double
- lf corresponding to long float (double)
- g
- e: with an exponential format
Comments: