c++ program to add two numbers
using namespace std;
int firstNumber, secondNumber, sumOfTwoNumbers;
cout << "Enter two integers: ";
cin >> firstNumber >> secondNumber;
// sum of two numbers in stored in variable sumOfTwoNumbers
sumOfTwoNumbers = firstNumber + secondNumber;
// Prints sum
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;
Enter two integers: 6
6 + 4 = 10
- 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 sum Of Two Numbers variable.
- Finally, sum Of Two Numbers is displayed on the screen.