C++ Program to add two integers


This content was proof-read by Grammarly. You can Try Grammary for FREE

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

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: