VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-find-remainder-without-using-modulo-or-operator/

⇱ Program to find remainder without using modulo or % operator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to find remainder without using modulo or % operator

Last Updated : 23 Jul, 2025

Given two numbers 'num' and 'divisor', find remainder when 'num' is divided by 'divisor'. The use of modulo or % operator is not allowed.
Examples : 

Input: num = 100, divisor = 7
Output: 2

Input: num = 30, divisor = 9
Output: 3

Method 1 :

Output : 

2

Time Complexity: O(1) 

Auxiliary Space: O(1)
This method is contributed by Bishal Kumar Dubey
 

Method 2


The idea is simple, we run a loop to find the largest multiple of 'divisor' that is smaller than or equal to 'num'. Once we find such a multiple, we subtract the multiple from 'num' to find the divisor.
Following is the implementation of above idea. Thanks to eleventyone for suggesting this solution in a comment. 
 

Output : 

2

Time Complexity: O(n) 

Auxiliary Space: O(1)


 

Method 3


Keep subtracting the denominator from numerator until the numerator is less than the denominator. 
 

Output : 

2

Time Complexity: O(n) 

Auxiliary Space: O(1)


 

Comment