Tuesday, July 5, 2011

Reading double in C using scanf()

Usually we use %f for reading float type data. But if you use %f to read a data of type double, the the compiler will show a warning. So to read double data types the format specifier is %lf

A sample program is shown below.

#include <stdio.h>
main(void)
{
double a;
scanf("%lf",&a);
printf("a=%lf",a);
}  

3 comments:

Anonymous said...

Thanks a lot

Anonymous said...

Thanks
and what about long double?

Anonymous said...

%lf is needed for scanf but not for printf. In printf %f is enough even for doubles.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes