Addition and Subtraction in C++
Addition in C++
To add two number is C++ just declared two variable and assign value to these variable and the write the formula for addition.
For example
Method 1
#include<iostream.h>
int main ()
{
int a=3;
int b=5;
cout<<a+b;
return 0;
system(“pause”);
};
But if you want to modify your result further so the use the alternative method for addition Method 2 In this method we declared three variables and then we assign value to first two variables and then assign formula to third variable as show in the given example.
Example
#include<iostream.h>
Int main()
{
int a=3;
int b=5;
int c;
c=a+b;
return 0;
system(“pause”);
};
Know we can modify our result if we want to add 5 to our answer so we can add it easily as show blew.
c= (a+b)+5;
or
c=c+5;
Subtracting two numbers in C++
Subtracting two numbers in C++ is same as adding two numbers but only the minus sigh is us as show in the example given blew.
Example
#include<iostream.h>
int main()
{
int a=3;
int b=5;
int c;
c=a-b;
return 0;
system(“pause”);
};