Learn C++ - Add 2 number with C++

In this Tutorial,  we will learn to Input 2 numbers and Add them , you should have basic knowledge of setting up and opening Turbo C ++ compiler









Program:

#include<iostream.h>
#include<conio.h>

void main
{
clrscr();


int a,b,c;
cout<<"Enter First No.";
cin>>a;
cout<<"Enter second No.";
cin>>b;

c=a+b;
cout<<"Sum of Two numbers is :"<<c;
getch();
}


Explanation:

  • After clrscr(); we have declared the type of Data that will stored in a,b and c. Here we are going to add 2 integer and there result should be in form of Integer. Therefore we have used :
    int a,b,c;  , It will take only integer value not decimal . To enable C++ to use Decimal replace int with float
  • After that we are commanding the program to get two number from User.  Program will calculate the Value and store the Value in variable c
  • After that we are asking the Program to Output the Value of C. 
  • You can use various operator instead of + , For e.g use - to subtract , / to divide  and * to multiply