- Related Questions & Answers
- C++ Program to Find Quotient and Remainder
- C Program to find sum of two numbers without using any operator
- Division without using ‘/’ operator in C++ Program
- remainder() in C++ program
- What is modulo % operator in Python?
- Find largest element from array without using conditional operator in C++
- Maximum of four numbers without using conditional or bitwise operator in C++
- Program to find Quotient and Remainder in Java
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
- C Program to Compute Quotient and Remainder?
- Program to find the Largest Number using Ternary Operator in C++
- Program to find remainder when large number is divided by 11 in C++
- Program to find remainder when large number is divided by r in C++
- remainder() in C++
- Finding sum of first and last digit using divide and modulo operator in C language

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two numbers, N and D. Our task is to create a *Program to find remainder without using modulo or % operator in C++*.

**Problem description** − We need to find the remainder that will be left after dividing the number N by D. But we cannot use the modulo or % operator for this.

**Let’s take an example to understand the problem**

N = 53 D = 3

2

To find the remainder, a simple approach is to find the number less than N which is the multiple of D. And the substrate the number from N. To return the remainder.

**Program to illustrate the working of our solution**

#include <iostream> using namespace std; int findRem(int N, int D) { int i ; for(i = 0; ;i++) { if(D * i >= N) break; } return N - (D * (i-1)); } int main(){ int N = 45, D = 6 ; cout<<"The remainder after dividing "<<N<<" by "<<D<<" is"<<findRem(N, D); return 0; }

The remainder after dividing 45 by 6 is 3

Another solution is by using the integer value of the quotient of the dividing which can be extracted directly by initializing it to an int value in C++. Then multiplying it with D. And subtracting the value from N gives the remainder.

**Program to illustrate the working our solution**

#include <iostream> using namespace std; int findRem(int N, int D) { int Q = N/D; int R = N - (D * Q); return R; } int main(){ int N = 45, D = 6 ; cout<<"The remainder after dividing "<<N<<" by "<<D<<" is"<<findRem(N, D); return 0; }

The remainder after dividing 45 by 6 is 3

Advertisements