Difference between %f and %lf | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Difference between %f and %lf

#include <stdio.h> int main() { double a,b,c; scanf("%f %f",&a,&b); c=b/0.02; if(c<a){ printf("Dollars"); }else{ printf("Pesos"); } return 0; } /* when using “%lf” it works ,so what’s the difference between “%f” and “%lf” */

14th Apr 2020, 2:19 PM
Zhengrong Yan
Zhengrong Yan - avatar
1 Answer
+ 2
For printf, arguments of type float are promoted to double so both %f and %lf are used for double. For scanf, you should use %f for float and %lf for double.
14th Apr 2020, 3:00 PM