I had a problem trying to print a fraction in C. How I can print the fraction as the number I defined below. Here is my code:
#include<stdio.h>
int main()
{
printf("%.4f\n", 153/400);
return 0;
}
Any help will appreciated.
I had a problem trying to print a fraction in C. How I can print the fraction as the number I defined below. Here is my code:
#include<stdio.h>
int main()
{
printf("%.4f\n", 153/400);
return 0;
}
Any help will appreciated.
You doing integer division now which will only result in integer. You have to perform floating point division. You can easily achieve this by writing 400.0 instead of 400 or casting one of the operand (or both if you will) to float like 153/(float)400.
Edit: As @Erwan Daniel rightly noted you have to use 400.0f to have a float literal, since on default it will be double.