Program to add two number

0 Suresh Chand March 28, 2021

In this example, We will learn how to add two number entered by user.

This program will ask two number. After user provide two numbers, then program will print the sum of that two number.

#include <iostream>
using namespace std;

int main()
{
    int num1, num2, sum;
    
    cout << "Enter two integers: ";
    cin >> num1 >> num2;

    // sum of two numbers in stored in variable sum
    sum = num1 + num2;

    // Prints sum 
    cout << num1 << " + " <<  num2 << " = " << sum;

    return 0;
}

The output of above program is

Enter two integers: 10 22
10 + 22 = 32

We have declared three variables on this program. Two variables (num and num1) are used to store the number given by the user and then after we will add these numbers and store them in the sum variable. Finally, We will print that sum using cout object.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System