Match each printf format specifier to the type of the corresponding argument. Use %d for int and %f for double.
int count = 3;
double temperature = 23.5;
printf("%d\n", count);
printf("%.1f\n", temperature);The output is 3 and 23.5. %.1f prints one decimal place. A float argument is promoted to double when passed to printf, so %f works for float too.
Check the declaration
A mismatch, such as passing an int for %f, causes undefined behavior. Check the variable declaration and compiler warnings rather than trying to infer a rule from the output.
Do not confuse printf with scanf
For scanf input, use %f with a pointer to float and %lf with a pointer to double.