C++ Program to find remainder without using modulus operator


In this program, You will learn how to find remainder without using modulus operator in C++.


0 = 10 % 5

5 = 5 % 10


Example: How to find remainder without using modulus operator in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int a, b;
    cout << "Enter First Number :";
    cin >> a;
    cout << "\nEnter Second Number :";
    cin>>b;

    while (a >= b) {
        a = a - b;
    }
    cout << "\nRemainder is :" << a;

    return 0;
}

Output:

Enter First Number :8
Enter Second Number :4
Remainder is :0