Table of Contents
A modulo operator in c returns the remainder of a division, not a quotient. This program finds remainder without using the modulo (mod) operator.
This program is a frequently asked question for aptitude tests and job interviews. So, you must try the write the program yourself and then compare your results with the solution given on this page.
Problem Definition
The program receives an input number – a divisor and a dividend. The quotient of the division is easily obtained using the division operator (/).
Now, you cannot use the modulo operator and have to find another way to find the remainder. You can do it in two steps listed below.
- Find an intermediate number by multiplying quotient * divisor.
- subtract the intermediate number from the dividend.
For example, divisor = 10, dividend = 53, find the remainder.
\begin{aligned}&
quotient = 53 / 10 = 3 \\ \\
&intermediate \hspace{2mm} number = 5 * 10 = 50\\ \\
&remainder = dividend - intermediate \hspace{2mm} number\\ \\
&remainder = 53 - 50 = 3
\end{aligned}See the flowchart for this program given below to understand this logic.
Flowchart – Remainder without Modulo Operation

Program Code – Remainder without Modulo Operation
#include <stdio.h>
#include <conio.h>
void main()
{
int n1,n2,quotient,reminder;
clrscr();
printf("Enter two numbers:\n");
scanf("%d %d",&n1,&n2);
quotient = n1/n2;
reminder = n1 - quotient * n2;
printf("Remainder = %d\n",reminder);
getch();
}#include <iostream>
using namespace std;
int main() {
int n1, n2, quotient, remainder;
cout << "Enter two numbers:" << endl;
cin >> n1 >> n2;
quotient = n1 / n2;
remainder = n1 - quotient * n2;
cout << "Remainder = " << remainder << endl;
return 0;
}import java.util.Scanner;
public class RemainderCalculation {
public static void main(String[] args) {
int n1, n2, quotient, remainder;
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers:");
n1 = sc.nextInt();
n2 = sc.nextInt();
quotient = n1 / n2;
remainder = n1 - quotient * n2;
System.out.println("Remainder = " + remainder);
sc.close();
}
}# Program to calculate remainder using quotient logic
print("Enter two numbers:")
n1, n2 = map(int, input().split())
quotient = n1 // n2
remainder = n1 - quotient * n2
print("Remainder =", remainder)Output
The larger number 255 is the dividend, and the smaller number 33 is the divisor. The division does not return quotient, but the remainder 24.
Enter two numbers:255 33
Reminder = 24