Reading in double values with scanf in c Reading in double values with scanf in c c c

Reading in double values with scanf in c


Use the %lf format specifier to read a double:

double a;scanf("%lf",&a);

Wikipedia has a decent reference for available format specifiers.

You'll need to use the %lf format specifier to print out the results as well:

printf("%lf %lf",a,b);


As far as i know %d means decadic which is number without decimal point. if you want to load double value, use %lf conversion (long float). for printf your values are wrong for same reason, %d is used only for integer (and possibly chars if you know what you are doing) numbers.

Example:

double a,b;printf("--------\n"); //seperate linesscanf("%lf",&a);printf("--------\n"); scanf("%lf",&b);printf("%lf %lf",a,b);


You are using wrong formatting sequence for double, you should use %lf instead of %ld:

double a;scanf("%lf",&a);