Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+6 votes
asked Sep 21, 2023 by Dave Vonn Bayeta (180 points)

2 Answers

0 votes
answered Sep 21, 2023 by Peter Minarik (88,520 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!

0 votes
answered Nov 16, 2023 by Gulshan Negi (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 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...