Operators in C++
Operators are key components in any programming language. Operators can be classified into many types listed as follows…
- Arithmetic Operators
- Assignment Operators
- Logical Operators
- Relational Operators
- Unary operators
- Ternary Operators or Conditional
Operators
- Bitwise operators
Each and
every operators are detailed explained here.
1.Arithmetic
Operators
As the name indicates, these are the
operators for perform arithmetic expressions. It has ‘+’ for addition, ’-‘ for
subtraction, ‘/’ for division, ‘*’ for multiplication and ‘%’ for mod
operation.
Each one is
expressed in coding.
C++ program
to use Arithmetic operators:
This program reads two integers
and two floating values from the user as input.
It uses all
arithmetic operators and displays the output.
Program:
#include
<iostream>
using
namespace std;
int main()
{
int a,b,c=0;
float d,e,f =0.0;
cout<<" Enter the two integers
:"<<endl;
cin>> a>> b;
cout<<"Enter the two float
numbers :"<<endl;
cin>> d >>e;
c = a + b;
f = d - e;
cout<<"The sum of two numbers
are:"<< c <<endl;
cout<<"The subtraction of two
numbers are:" <<f <<endl;
cout<<"The multiplication of two
integers are:"<<a*b<<endl;
cout <<"The Division of two
integers are:"<<a/b<<endl;
cout<<"The mod value of two
numbers are:"<< a/b<<endl;
return 0;
}
Output:
Compile and
run the program to get the output.
Enter the
two integers :
34 17
Enter the
two float numbers :
23.45 12.23
The sum of
two numbers are:51
The
subtraction of two numbers are:11.22
The
multiplication of two integers are:578
The
Division of two integers are:2
The mod
value of two numbers are:2
That’s all.
All arithmetic operators are used here. Hope, you understood the concept. Remaining
operators are explained in another blog. Keep coding!!!
Comments
Post a Comment