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.
using namespace std;
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;
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.
Get the latest tutorials, examples and projects updates.
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