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


Tags: ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.