Difference between %f and %lf | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

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 Respuesta
+ 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
Rohit