Free programming examples and instructions

CPP Program to Add any two numbers

c plus plus program for how to add two numbers

by Krishna viswambharan

Posted on 30 Jul 2018 Category: C plus plus Views: 16

Edited on 30 Jul 2018

CPP Program to Add any two numbers

This is a simple CPP program to add any two numbers. In this program, the user is asked to enter two  numbers(integers). The result is calculated and displayed on the screen.

using namespace std;
int main()
    int num1, num2, sum; 
    cout<<"Enter first number: ";
    cout<<"Enter second number: ";

    // sum of two numbers in stored in variable sum
    sum = num1+num2;
    // Prints sum 
    cout<<"Sum of two numbers=" <<sum;     
    return 0;

In the above program the entered two integers are stored in the variable num1 and num2 respectively. These two  numbers are added and sum is stored  in another variable, sum and the value in the variable sum is displayed on the screen.

When the above C++ source code is compile and executed, it will produce the following output:


C code for the same program is also available

Leave a Comment: