C++ Example - Implementing Addition of Two Numbers

C++ Examples

Use C++ to get user input of two numbers, add the two numbers, and then output to the screen:

Example

#include <iostream> using namespace std; int main() { int firstNumber, secondNumber, sumOfTwoNumbers; cout << "Enter two integers:"; cin >> firstNumber >> secondNumber; //Addition sumOfTwoNumbers = firstNumber + secondNumber; //Output cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers; return 0; }

The output of the above program execution is:

输入两个整数: 
4
5
4 + 5 = 9

C++ Examples

other extensions