Skip to main content

Welcome to Coding 4 Programming

Addition of Two Binary Numbers | Function | Python

Addition of two Numbers | User Friendly |C++

 

Program of Addition of Two Numbers entered by the user in C++


#include<iostream.h> 
#include<conio.h> 
void main()
{
 clrscr();
 cout<<"\n\n\t Welcome to Coding 4 Programming";
 int a,b,c;
 cout<<"\n\t Enter First Number=";
 cin>>a;
 cout<<"\n\t Enter Second Number=";
 cin>>b;
 c=a+b;
 cout<<"\n\n\t The Addition of "<<a<<" and "<<b<<" is "<<c;
 getch();
}


Compiler Screen:

Addition in C++
Compiler Screen

Output Screen:

Addition in C++
Output Screen

Illustration of above Coding:

1. In Header Files (line 1 and line 2) .h is not required in some compilers.

2. iostream.h (line 1) header file is used for input (cin) and output (cout) services.

3. conio.h (line 2) header file is used for clrscr() and getch() functions.

4. Instead of void main (line 3) some may use int main.

5. Some new compiler required using namespace std; before main function (line 3).

6. clrscr() (line 5) function is used for clear the previous output on output screen.

7. \n is used for new or next line.

8. \t is used for giving tap space.

9. In line 7, we declared three variable of integer data type named (identifier) as ab and c. a and b for the number which user want to be add and c for storing the result (addition of a and b).

10. In line 8 and 10, program will display message on output screen to user for entering value of a (line 8) and b (line 10).

11. In line 9 and 11, program will take value of a (line 9) and b (line 11) entered by the users during running of program. 

12. In line 12, we are giving formula (a+b) to the program for addition of a and b and assigning the result in variable c, you can also change the formula for the program of Subtraction and Multiplication.

13. cin (line 9 and line 11) is used for taking the value of a (line 9) and b (line 11).

14. cout (line 6, 8, 10 and 13) is used for the display anything (content) on output screen.

15. getch() (line 14) function is used for freezing the output screen.

16. Braces i.e., {} (line 4 and line 15) is used for the block. That means from line 4 to line 15 is single block.

Comments

Popular Posts