9th Aug 2019, 11:23 AM
Shubham Kumar
Shubham Kumar - avatar
3 Answers
+ 13
Shubham Kumar format specifier for double data type is %lf so use that and give an address to the variable https://code.sololearn.com/cTtBek23Z0tX/?ref=app
9th Aug 2019, 11:35 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
when it comes to printf the format specifier %f is one way to print doubles. if you attempt to pass a float to printf, it'll be promoted to double before printf receives it. %lf is also acceptable. when it comes to scanf, receiving input it is different. for input you're passing a pointer (in your code you forgot to put the address operator before the variable in scanf), which is not promoted, so you have to specify to scanf wether you want to read a float or a double: &f - if you want to read a float &lf - if you want to read a double &Lf - if you want to read a long double (&Lf is for printf as well the format specifier for long double)
9th Aug 2019, 1:15 PM
notqueued
notqueued - avatar
+ 1
When you use scanf you should pass the pointer to the variable you want to assign. You should write: scanf("%f", &sam);
9th Aug 2019, 11:33 AM
Paolo Luigi Rinaldi
Paolo Luigi Rinaldi - avatar