Add two integer numbers using different ways in C++ programming and print the sum on the output screen. In this tutorial, you can learn how to add two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"The Output is: "<<5 + 6; //adding 5 and 6 and printing.
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 5; //assigning 5 to 'a'.
int b = 6; //assigning 6 to 'b'.
int c = a + b; //adding 'a' and 'b' values and assigning to 'c'.
cout<<"The output is: "<<c; //printing 'c' value.
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a, b, c;
a = 50;
b = 25;
c = a + b;
cout<<"The sum of "<<a<<" and "<<b<<" is: "<<c; //printing values and Sum.
getch();
}
#include<iostream.h>
#include<conio.h>
int a, b, c; //declaring 'a', 'b' and 'c' as a Global variable.
void main()
{
a = 50;
b = 25;
c = a + b;
cout<<"The sum of "<<a<<" and "<<b<<" is: "<<c; //printing values and Sum.
getch();
} //when U declare variable Before Main and after Labrary then called
//Global Variable Declaration.
//and when U declare variable After Main and Inside any Body then called
//Local Variable Declaration.