0
In "printf", if i use "%f" it was working. But when i used "%d" it was not working. Why? I'm so beginner . Don't mind ! -_-
include <stdio.h> int main() { int a,b; float c; scanf("%d %d %f",&a,&b,&c); printf ("%d",a+b+c); return 0; }
2 Respuestas
+ 3
If you want to print it as integer, you need explicit type cast:
printf("%d", (int) (a+b+c));
+ 2
So, basically, C automatically converts your values to a float type. Because of the difference in their structure (representation in memory) you need to specify the right type in your template string (%f - for float in your case)