Below you can see the code for finding the modulus of both to numbers. First, we make three objects of any data type and than take input of two objects. Than use modulus between them. And giving the value of modulus of both numbers of object three. Then output the number three and you can watch the modulus of both numbers.
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
int num1,num2,num3;
cout<<"Enter first number : ";
cin>>num1;
cout<<"Enter secod number : ";
cin>>num2;
num3=num1%num2;
cout<<"Num3 : "<<num3;
}
Output:
Enter first number : 5
Enter secod number : 4
Num3 : 1
So, you can watch the output and can show how we can use modulus operator in c++.
0 Comments