# How to get a decimal quotient in C(Turbo C)?

answered Sep 21, 2023 by (89,550 points)

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!

answered Nov 16, 2023 by (1,580 points)

Well, here is the complete program to get a decimal quotient in C. I hope it will help you.

#include <stdio.h>

int main() {
int numerator, denominator;

// Input numerator and denominator
printf("Enter numerator: ");
scanf("%d", &numerator);

printf("Enter denominator: ");
scanf("%d", &denominator);

// Check for division by zero
if (denominator == 0) {
printf("Error: Division by zero.\n");
} else {
// Use float or double for decimal quotient
float result = (float)numerator / denominator;

// Print the decimal quotient
printf("Decimal Quotient: %f\n", result);
}

return 0;
}

Thanks