C++ Program to compute remainder

Simple C++ Program to compute remainder
To compute remainder in C++, there is a operator by which remainder can be computed directly and that is %. For example if two numbers are 12 and 7 then to compute remainder, when we divide 12 by 7, we use 12%7. 12%7 = 5.
 
/* C++ Program to compute remainder */
#include<iostream>
using namespace std;
int main()
{
 int a,b,rem;
 cout<<"Enter two numbers: "<<endl;
 cout<<"Enter first number: ";
 cin>>a;
 cout<<"Enter second number: ";
 cin>>b;
 rem=a%b;
 cout<<"Remainder of "<<a<<"/"<<b<<" = "<<rem;
 return 0;
}
/* End of program */
 
Another C++ Program to compute remainder using function
 
/* C++ Program to compute remainder */
#include<iostream>
using namespace std;
int FindRemainder(int a,int b)
{
 int rem;
 rem=a%b;
 return rem;
}
int main()
{
 int a,b,rem;
 cout<<"Enter two numbers: "<<endl;
 cout<<"Enter first number: ";
 cin>>a;
 cout<<"Enter second number: ";
 cin>>b;
 rem=FindRemainder(a,b);
 cout<<"Remainder of "<<a<<"/"<<b<<" = "<<rem;
 return 0;
}
/* End of program */




Popular posts from this blog