C Example for Beginners: C Program to Compute Quotient and Remainder

(C programming Example for Beginners)

 

C Program to Compute Quotient and Remainder

In this example, you will learn to find the quotient and remainder when an integer is divided by another integer.


Program to Compute Quotient and Remainder

#include <stdio.h>
int main(){
    int dividend, divisor, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", &dividend);
    printf("Enter divisor: ");
    scanf("%d", &divisor);

    // Computes quotient
    quotient = dividend / divisor;

    // Computes remainder
    remainder = dividend % divisor;

    printf("Quotient = %dn", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}

Output

Enter dividend: 25
Enter divisor: 4
Quotient = 6
Remainder = 1 

In this program, the user is asked to enter two integers (dividend and divisor). They are stored in variables dividend and divisor respectively.

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

Then the quotient is evaluated using / (the division operator), and stored in quotient.

quotient = dividend / divisor;

Similarly, the remainder is evaluated using % (the modulo operator) and stored in remainder.

remainder = dividend % divisor;

Finally, the quotient and remainder are displayed using printf().

printf("Quotient = %dn", quotient);

printf("Remainder = %d", remainder);

 

C Program to Compute Quotient and Remainder

Sign up to get end-to-end “Learn By Coding” example.



Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.