Remainder of Number Using C++ Programming

Explanation of Program Code:

For input and output streams, you have to include library files that is iostream or iostream.h for older version of compiler or IDE.Then include the basic function use in every c++ program coding that is main function.Its syntax is as follows  int main(){}. Include the return statement which means now there is no more statement to execute.
In order to find remainder how many variables you need, yes three variables.Two of them for the numbers and one for the remainder.Data type depends the numbers if they have no decimal value then type will be integer type otherwise go for float or double data types.

For remainder use the modulus operator % .Rest is simple, result will be store in varaible rem as define in program.In order to avoid again and again execution of program code, read this article and use this.

Program code:
#include<iostream>
using namespace std;
int main()
{
int num1, num2 , rem ;
cout<<  " Enter ist number   =  ";
cin>>num1;
cout<<endl;
cout<<  " Enter 2nd number   =  ";
cin>>num2;
cout<<endl;
rem = num1 % num2;
cout<< rem << " is the remainder ";

return 0;
}

Output:
Enter ist number
5
Enter 2nd number
2
1 is the remainder

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.