C Program to find Reminder without Modulo Operation

Previous Article
Next Article

The program to find remainder is usually implemented using a modulo operator. You get the immediate result with any difficulty. However, there is another way to achieve the same results without using the modulo operator.

This is a frequent question asked in lot of C programming interviews to test the aptitude of the candidates. So it is a well known problem and it solution is also known to most of the C learners.

This program is written using Turbo C++ 3.0 compiler installed on a windows XP 32-bit system. You are free to use any standard C compiler and still achieve the same results.

Problem Definition

The program receives an input numbers – divisor and a dividend. The quotient of the division is easily obtained using the division operator (/).

Now we cannot use the modulo operator and have to find another way to find the remainder.There are two steps to do that

  1. Find and intermediate number by multiplying quotient * divisor.
  2. subtract the intermediate number from dividend.

For example, divisor = 10, dividend = 53 , find the remainder.

quotient = 53 / 10 = 3

intermediate number = 5 * 10 = 50

remainder = dividend – intermediate number

remainder = 53 - 50 = 3

Check the flowchart below to understand this logic.


Flowchart - Remainder without Mod Operation
Flowchart – Remainder without Mod Operation

Program Code

void main()
int n1,n2,quotient,reminder;
printf("Enter two numbers:\n");
scanf("%d %d",&n1,&n2);
quotient = n1/n2;
reminder = n1 - quotient * n2;
printf("Remainder = %d\n",reminder);



The output of the above program is given below.


Output-Remainder without Modulo
Output-Remainder without Modulo
Previous Article
Next Article