✓ Link copied to clipboard
C 📅 July 2, 2026 ⏱ 5 min read

C Program to Compute Quotient and Remainder Easily

C Program to Compute Quotient and Remainder Easily

You've been doing a lot of division in your C class, but what’s the remainder when you divide 20 by 3? This program will compute both the quotient and the remainder for you.

We're gonna use simple division in C. Let’s dive into this quick program.

Prerequisites for the C Program to Compute Quotient and Remainder

Here's what you need to know and have:

  • Variable declaration using int type.
  • The division "/" and remainder "%" operators.
  • <stdio.h> for input and output functions.
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler.

Source Code of C Program to Compute Quotient and Remainder

Let's see the source code for this program. We'll use standard input and output functions to achieve our goal.

quotient_remainder.cC▶ Run
#include <stdio.h>

int main() {
    int a, b, quotient, remainder;
    // Read two integers from the user
    printf("Enter the dividend: ");
    scanf("%d", &a);
    printf("Enter the divisor: ");
    scanf("%d", &b);

    // Calculate quotient and remainder
    quotient = a / b;
    remainder = a % b;

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

    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Compute Quotient and Remainder Program

Here's what you'll see when you run this program:

OutputConsole
Enter the dividend: 20
Enter the divisor: 3
Quotient = 6
Remainder = 2
Output of C Program to Compute Quotient and Remainder
Output of C Program to Compute Quotient and Remainder

Algorithm to Compute Quotient and Remainder in C

Computing the quotient and remainder involves dividing one number by another. Here's how this program goes about it:

  1. Read the dividend and divisor from the user.
  2. Calculate the quotient by dividing the dividend by the divisor.
  3. Calculate the remainder using the modulus operator %.
  4. Output the calculated quotient and remainder.
flowchart TD
  A([Start]) --> B[/Read a and b/]
  B --> C[quotient = a / b]
  C --> D[remainder = a %% b]
  D --> E[/Print quotient and remainder/]
  E --> F([End])
Flowchart: the algorithm step by step

How the C Program to Compute Quotient and Remainder Works

This program takes two integers from the user and performs arithmetic to find the quotient and remainder. Let's break it down:

  • The program starts by including the header file <stdio.h> to allow input and output operations.
  • Inside the main() function, declare four int variables: a, b, quotient, and remainder.
  • Use printf and scanf to read the dividend and divisor from the user.
  • The division a / b computes the quotient and stores it in the variable quotient.
  • The modulus operation a % b computes the remainder and stores it in the variable remainder.
  • Finally, printf commands output the calculated quotient and remainder to the user.
  • The program ends by returning 0 from main(), indicating successful execution.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What does the remainder operator (%) do in C?

🎉Correct! The % operator gives the remainder of a division.
🤔Not quite. Remember, % is about what's left after division.

Time and Space Complexity of the C Program to Compute Quotient and Remainder

Let's consider how efficient this program is in terms of time and space.

Time Complexity: The time complexity is O(1) because the operations a / b and a % b each take a constant amount of time, regardless of the input size. The same set of operations is performed every time you run the program.

Space Complexity: The space complexity is also O(1) because we only store a small fixed number of variables: a, b, quotient, and remainder. This does not grow with input size.

⚠️

Common mistake: Dividing by zero isn’t defined in C, and it'll lead to a runtime error. Just make sure your divisor isn’t zero.

Key takeaway: The % operator shows what’s left after dividing one number by another.

FAQs About Computing Quotient and Remainder in C

Here are some common questions students ask about this program.

Nope, dividing by zero isn’t allowed in C and it'll cause a runtime error.
The % operator gives you the remainder of a division.
Yep, if the dividend's negative, the remainder can be negative too.
The / operator gives the quotient; the % operator gives you the remainder.
Quotient and remainder operations are handy for scheduling tasks, dividing resources, and doing modular arithmetic.

If you found this program helpful, check out these related programs:

Conclusion

If you’re scheduling tasks or splitting resources, knowing how to compute quotients and remainders really helps. Try modifying this code for more inputs or even float values. It’s great practice with arithmetic in C.

Practice more C programming with our quiz and test out the code yourself in the EduSeekho online compiler.