Share your content and reach out to more developers by submitting them at Abundantcode.com - Developer Community Site

C++ Program to add two integers

Problem

Write a program in C++ to add two integers and display the result on the screen.

C++ Program to add two integers

#include <iostream>
using namespace std;

int main()
{
    int input1, input2, result;
    // Abundantcode - Read first number
    cout << "Enter first number : ";
    cin >> input1;
    // Abundantcode - Read second number
    cout << "Enter second number : ";
    cin >> input2;
    
    // sum of two numbers stored in the variable
    result = input1 + input2;

    // Display the results
    cout << input1 << " + " <<  input2 << " = " << result;     

    return 0;
}

Output

Enter first number : 8                                                                                                                                                           
Enter second number : 2                                                                                                                                                                 
8 + 2 = 10

Leave Your Comment