Arithmetic operators
Arithmetic operators are:
- * (Multiply), /(divide), %(Modulas)-It's priority is most
- + - It's priority is least.
i) Multiplication Operator:
- This operator multiplies two operands.
- If in any expression if there is * (multiplication) and + (Addition). Then according to precedence rule * (multiplication) is first solved.
- If in arithmetic operators, operators are the same then it is solved from left to right.
- i.e its associativity is left to right.
Program
#include <stdio.h>
#include<conio.h>
int main()
{
int a;
a=2*3;
printf("Answer of multiplication operator is %d",a);
getch();
}
Output:
Answer of multiplication operator is 6
ii) Integer divide Operator:
Examples:
2/3 ? = 0
Instead of 0.6.
13/2 =6
instead of 6.5.
Program:
#include <stdio.h>
#include<conio.h>
int main()
{
int a;
a=2/3;
printf("Answer of Integer divide operator is %d",a);
getch();
}
Output:
Answer of Integer divide operator is 0
iii) Modulo Operator:
The remainder obtained after the division operation on two operands is known as modulo operation.
The operator for doing modulus operation is "%".
Ex. a%b=c
where c is the remainder obtained when a is divided by b.
Example:
2%3 ? = 2
Instead of 0.6/0
13%2 = 1
instead of 6.5.
#include <stdio.h>
#include<conio.h>
int main()
{
int a;
a=2%3;
printf("Answer of modulo operator is %d",a);
getch();
}
Output:
Answer of modulo operator is 2
4+1-2
It is solved from left to right and ans. is 3.
Here + is operated first.
4-2+1
it is solved from left to right and ans. is 3.
Here - is operated first.
Program
#include <stdio.h>
#include<conio.h>
int main()
{
int a;
a=4-2+1;
printf("Answer of Addition and subtraction operator is %d",a);
getch();
}
Output:
Answer of Addition and subtraction operator is 3
Comments
Post a Comment