When I enter 2, I wish to get this output:
value: 2.4
But when I do the multiplication, I am getting this:
value: 2.400000
This is my code:
#include <stdio.h>
int main()
{
float num;
float result;
printf("Number: ");
scanf("%f", &num);
result = num * 1.2;
printf("Result: %f", result);
}
What can I do?
>Solution :
You need to change your printf() to this:
printf("Result: %.1f", result);
The number after the . and before the f is the precision that specifies the number of digits after the decimal point of a floating-point value.