Skip to content
Home » Blog » C++ Program to Add Two Numbers

C++ Program to Add Two Numbers

Add Two Number

In this Program, you’ll learn to Add Two Number.

Here the user is asked to enter two numbers (integers).

When the user enters the number the sum of those two integers are stored in a variable and displayed on the output screen.

To understand this Program for the addition of two numbers, you should have knowledge of Learn C++ programming.

Program to Add Two Number or Integers

#include <iostream>
using namespace std;

int main()
{
    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;     

    return 0;
}

Output

Enter two integers: 4
5
4 + 5 = 9

In this program, the 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.

Ask your questions and clarify your/others doubts on Addition of Two Numbers by commenting. Documentation.

Please write to us at [email protected] to report any issue with the above content or for feedback.

Related Programs