Consider the below code:
#include <stdio.h>
int main()
{
int i = 3 / 2;
float f = 3.0f / 2.0f;
printf("integral division: 3 / 2 = %d\n", i);
printf("floating point division: 3 / 2 = %f\n", f);
return 0;
}
If you do an integral division, the result is also an integral number, i.e., no fractional parts. So 3 / 2 = 1, because all the fractional parts are ignored.
If you want to keep the fractions, you need to use a floating point division and store the result in a floating point variable. Such types are float and double (double precision).
Floating point numeric literals have a fraction part, e.g. 1.0 is a floating point number while 1 is an integral number. To tell the compiler you want to work with the float type use the f suffix after the number, e.g.: 3.14f is a float numeric literal.
If you omit the f suffix, the type of the numeric literal is double. For instance, 3.14 is a double numeric literal.
I hope this clears things up.
Good luck!