Easy Tutorial
❮ Cpp Examples Hcf Gcd Binary Operators Overloading ❯

C++ Example - Adding Two Numbers

C++ Examples

This C++ program takes two numbers as input from the user, adds them together, and then displays the result on the screen:

Example

#include <iostream>
using namespace std;

int main()
{
    int firstNumber, secondNumber, sumOfTwoNumbers;

    cout << "Enter two integers: ";
    cin >> firstNumber >> secondNumber;

    // Addition
    sumOfTwoNumbers = firstNumber + secondNumber;

    // Output
    cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;     

    return 0;
}

The output of the above program is:

Enter two integers: 
4
5
4 + 5 = 9

C++ Examples

❮ Cpp Examples Hcf Gcd Binary Operators Overloading ❯