double d;
scanf("%f", &d);
printf("%f", d);
result:
input: 10.3
output: 0.00000
Why? i think output should be 10.3 visual studio 2008.
double d;
scanf("%f", &d);
printf("%f", d);
result:
input: 10.3
output: 0.00000
Why? i think output should be 10.3 visual studio 2008.
For scanf()
, %f
is for a float
. For double
, you need %lf
. So,
#include <stdio.h>
main() {
double d;
scanf("%lf", &d);
printf("%f\n", d);
}
with input 10.3
produces 10.300000
.