Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input-output in C

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.

like image 407
Sergey Avatar asked Sep 04 '26 11:09

Sergey


1 Answers

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.

like image 167
Ramashalanka Avatar answered Sep 07 '26 00:09

Ramashalanka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!