-->

How to add Two numbers in C++ programming

 



How to add Two numbers in C++ programming


In this program, user is asked to enter two integers. These two integers are stored in variables firstNumber and secondNumber respectively. Then, the variables firstNumber and secondNumber are added using + operator and stored in sumOfTwoNumbers variable. Finally, sumOfTwoNumbers is displayed on the screen.

How to download

if you want to download the .CPP file then click on download button

Download

if it does not start click here

Download

Example: 1


#include<iostream>

using namespace std;

int main()

{

int a=21;

int b=41;

cout<<"The sum of two numbers are ="<<a+b<<endl;

}


Example: 2

#include<iostream>

using namespace std;

int main()

{

int a;

int b;

cout<<"Enter 1st Value : ";cin>>a;

cout<<"Enter 2nd Value : ";cin>>b;

int sum;

int multi;

float divi;

int sub;

sum = a+b;

sub = a-b;

multi = a*b;

divi = a/b;

cout<<"sum of a and b is: "<<sum<<endl;

cout<<"subtraction of a and b is: "<<sub<<endl;

cout<<"multiplecation of a and b is: "<<multi<<endl;

cout<<"division of a and b is: "<<divi<<endl;

}