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>
double a;


Anonymous said...

Thanks a lot

Anonymous said...

and what about long double?

Anonymous said...

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

Anonymous said...

for some reason I do that but it completely disregards my input and displays my number as 0.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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