Sunday 15 September 2019

C++ Add, Subtract, Multiply, Divide and Modulus of Two Numbers | C++ Code

Method#1
#include<iostream>
using namespace std;
void main()
{
int a=5. b=4,sum,pro,sub,div,mod; //Initializing variables

sum=a+b; //Adding Two Numbers

pro=a*b; //Multiplying numbers and storing result in variable 'pro'

sub=a-b; //Subtracting Two numbers

div=a/b; //Dividing Two Numbers

mod=a%b; //Finding Remainder of Two Numbers

cout<<"==========================================="<<endl;

cout<<"Sum: "<<sum<<endl;  //Displaying the Result of sum

cout<<"Product: "<<p<<endl; //Displaying the Result of  product

cout<<"Subtraction: "<<sub<<endl; //Displaying the Result

cout<<"Divsion"<<div<<endl;

cout<<"Remainder: "<<mod<<endl; //Displaying Modulus of Two numbers

cout<<"==========================================="<<endl;

return 0;
}



Method#2
#include<iostream>
using namespace std;

void main()
{

int a, b,sum,pro,sub,div;  //Initializing variables
cout<<"Enter 1st Number: "<<endl; //Prompt a message to user
cin>>a; //Taking input the in variable 'a'
cout<<"Enter 2nd Number: "<<endl; //Prompt a message to user
cin>>b; //Taking input the in variable 'b'
sum=a+b; //Adding Two Numbers
mod=a%b; //Finding Remainder of Two Numbers
pro=a*b; //Multiplying numbers and storing result in variable 'pro'

sub=a-b; //Subtracting Two numbers

div=a/b; //Dividing Two Numbers

cout<<"==========================================="<<endl;

cout<<"Sum of  "<<a<<" and "<<b<<" is "<<sum<<endl;  //Displaying the Result of sum

cout<<"Product of  "<<a<<" and "<<b<<" is "<<pro<<endl;  //Displaying the Result of  product

cout<<"Subtraction of  "<<a<<" and "<<b<<" is "<<sub<<endl;  //Displaying the Result

cout<<"Divsion of  "<<a<<" and "<<b<<" is "<<div<<endl;

cout<<"Modulus of  "<<a<<" and "<<b<<" is "<<mod<<endl;

cout<<"==========================================="<<endl;

return 0;

}

No comments:

Post a Comment