0% found this document useful (0 votes)
23 views2 pages

C++ Basic Sum Number

This C++ program asks the user to input two integers, adds them together, stores the sum in a variable, and displays the sum on the screen. It uses cin to input the numbers from the user, stores them in firstNumber and secondNumber variables, adds those variables together and stores the sum in sumOfTwoNumbers, and outputs the original numbers and sum using cout.

Uploaded by

zaidan fadhillah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

C++ Basic Sum Number

This C++ program asks the user to input two integers, adds them together, stores the sum in a variable, and displays the sum on the screen. It uses cin to input the numbers from the user, stores them in firstNumber and secondNumber variables, adds those variables together and stores the sum in sumOfTwoNumbers, and outputs the original numbers and sum using cout.

Uploaded by

zaidan fadhillah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C++ Program to Add Two Numbers

In this program, user is asked to enter two integers. Then, the sum of those
two integers is stored in a variable and displayed on the screen. Primary
tabs

Example: Program to Add Two Integers

#include <iostream>
using namespace std;

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

cout << "Enter two integers: ";


cin >> firstNumber >> secondNumber;

// sum of two numbers in stored in variable sumOfTwoNumbers


sumOfTwoNumbers = firstNumber + secondNumber;

// Prints sum
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;

return 0;
}

Output

Enter two integers: 4


5
4 + 5 = 9

In this program, user is asked to enter two integers. These two integers are
stored in variables firstNumber and secondNumber respectively.
Then, the variables firstNumber and secondNumber are added using + operator
and stored in sumOfTwoNumbers variable.
Finally, sumOfTwoNumbers is displayed on the screen.

You might also like