Dremendo Tag Line

Find remainder without modulus operator in C++

cin - Question 19

In this question, we will see how to input 2 integer numbers in C++ programming using the cin statement and find out the remainder without using modulus operator (%). To know more about cin statement click on the cin statement lesson.

Q19) Write a program in C++ to input 2 integer numbers and find out the remainder without using modulus operator (%).

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int a,b,q,r;
    cout<<"Enter 2 integer numbers\n";
    cin>>a>>b;
    q=a/b;
    r=a-(b*q);
    cout<<"Remainder="<<r;
    return 0;
}

Output

Enter 2 integer numbers
5
2
Remainder=1                
video-poster