Addition of two numbers in cpp

Addition of two numbers in cpp is very simple and easy program in cpp.

In this tutorial we are going to see very simple program to implement which is addition of two numbers in cpp.

Addition of two number in cpp  is a basic program.

Concepts we require to know form cpp are –

1. Basic input and output

2. Arithmetic operators in cpp

How to add two numbers

We take 2 numbers input from user and add two numbers and store addition in third variable and print addition we got.

Example :-

Number 1 = 10

Number 2 = 10

Sum = Number 1 + Number 2

Sum = 20

This is a simple way to perform addition of two numbers.

Algorithm for addition of two numbers in cpp 

  1. Start
  2. Declare variables a , b , c
  3. Take input number from user a and b
  4. Perform addition of numbers c = a + b
  5. Print addition c
  6. End

Now let’s see the program which implements the addition of two numbers program in cpp.

C++ program to add two numbers

123456789101112131415161718192021222324#include <iostream>using namespace std;int main(){//declare variablesint no1, no2, sum;//take user inputcout<<” \n Enter first number :”;cin>>no1;cout<<“\n Enter second number :”;cin>>no2;sum = no1 + no2;cout<<“\n Addition of two numbers = “<<sum;}

Output :-

addition of two numbers in c

Program Explanation :-

1. First, start with declaring the preprocessor directives 

2. Write the main function where execution starts

3. Next, we declare variables we require

no1 => to store first number

no2 => to store second number

sum => to store addition of numbers

4. Next line we take user input no1 and no2 for taking the input we use iostream.h standard functions which are

cout<<” \n Enter first number :”; => this is used to print the stream to the output screen so we printed the message which tell user to enter first number.

after this we write cin>>no1; => this used to read the input which user enters and store it in variable so using this we read no1 from user.

For example :- if user enters 10 then 10 is stored in no1.

no1 = 10

5. Next two line also same for reading no2 .

no2 = 10

6. Now we have 2 numbers no1 = 10 and no2 = 10 , so we perform addition of that two number.

sum = no1 + no2  => this statement adds no1 and no2 values and store result in sum so we got sum = 20.

7. Now we got the addition of numbers in sum .so print addition

cout<<“\n Addition of two numbers = “<<sum;

8. This prints the addition.