English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structures

C Language Files

C Others

C Language Reference Manual

C program to calculate quotient and remainder

Comprehensive Collection of C Programming Examples

In this example, you will learn how to calculate the quotient and remainder of one integer divided by another.

Program to calculate quotient and remainder

#include <stdio.h>
int main() {
    int dividend, divisor, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", ÷nd);
    printf("Enter divisor: ");
    scanf("%d", &divisor);
    //Calculate quotient
    quotient = dividend / divisor;
    //Calculate remainder
    remainder = dividend % divisor;
    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}

Output result

Enter dividend: 39
Enter divisor: 7
Quotient = 5
Remainder = 4

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

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

Then use/(division operator) to calculate the quotient and store it in the variable quotient.

quotient = dividend / divisor;

Similarly, use the modulus operator (%) to calculate the remainder and store it in the variable remainder.

remainder = dividend % divisor;

Finally, use printf() to display the quotient and remainder.

printf("Quotient = %d\n", quotient);
printf("Remainder = %d", remainder);

Learn AboutHow Operators Work in C Language ProgrammingMore Information.

Comprehensive Collection of C Programming Examples