Addition, subtraction, multiplication and division are basic operations of any programming language.
In C++, basic arithmetic operations are
1) Addition (+)
2) Subtraction (-)
3) Multiplication (*)
4) Division (/)
5) Increment by 1 (++)
6) Decrement by 1 (--)
Here I am demonstrating example of addition in C++, I want you guys to try other operations by your self. If you will find any problem, comment me.
Program Definition: Take two number from user and add them and display result.
How to solve: (Logic)
1) Take number 1 and save in no1 Variable.
2) Take number 2 and save in no2 variable.
3) Take no3 variable to save result of addition.
4) Add no1 and no2 and assign result in no3.
5) Display variable no3.
#include<stdio.h>
#include<iostream.h>
void main()
{
int no1,no2,no3;
//Clears output screen
clrscr();
cout<<"Enter first number: ";
cin>>no1;
cout<<"Enter second number: "; cin>>no2;
//Assign result of Addition of no1 and no2 to no3
no3=no1+no2;
cout<<"Addition of both numbers is: "<<no3;
getch();
}
Try it, and try with all arithmetic operations and share your experiences.
Enjoy Coding :)
No comments:
Post a Comment