Reputation: 37
#include<stdio.h>
int main()
{
float a=5.0;
printf("The Output is %.2f",(7/5)*a+12);
}
I thought the output is 19.00 but the output is 17.00. How this is possible?. Please guide me how the output is 17.00 came....
Upvotes: 2
Views: 136
Reputation: 1355
Your 7/5 gives an integer result, in this case 1. If you want to get 1.4 you need to change to 7.0/5.0 to get a float result, which will change the result.
Upvotes: 0
Reputation: 17848
7/5
is 1. That's integer division. Everything after that should be clear.
Upvotes: 10