C++ Program to Add Two Numbers
In this example, we take two numbers from the user and add those two numbers and display the sum. The below example takes two number and stores it in the variable “a” and “b” respectively. Another variable “sum” is declared that is used to store the addition of two numbers entered by the user.
Example:
#include<iostream.h> using namespace std; int main() { int a, b, sum; cout<<"Enter two number: "; cin>>a>>b; sum=a+b; cout<<"Sum of the two number is: "<<sum; return 0; }
The output of the above program is:
Output:
5
Sum of two number is: 10
In the output section of this program, at first, it displays “Enter two number”. After the user entered the numbers, the compiler displays the sum of these two numbers as shown above.