These operators are responsible for performing arithmetic or mathematical operations like addition (+), subtraction (-), multiplication (*), division (/), the remainder of the division (%), increment (++), and decrement (–).
Symbol |
Operator |
Description |
Syntax |
+ |
Plus |
Adds
two numeric values. |
a +
b |
– |
Minus |
Subtracts
right operand from left operand. |
a –
b |
* |
Multiply |
Multiply
two numeric values. |
a *
b |
/ |
Divide |
Divide
two numeric values. |
a /
b |
% |
Modulus |
Returns
the remainder after diving the left operand with the right operand. |
a %
b |
+ |
Unary
Plus |
Used to
specify the positive values. |
+a |
– |
Unary
Minus |
Flips
the sign of the value. |
-a |
++ |
Increment |
Increases
the value of the operand by 1. |
a++ |
-- |
Decrement |
Decreases
the value of the operand by 1. |
a-- |
SIMPLE C PROGRAMMING USING ARITHMETIC OPERATORS
// C program to illustrate the arithmatic operators
#include <stdio.h>
int main()
{
int a = 25,
b = 5;
// using
operators and printing results
printf("a
+ b = %d\n", a + b); // addition
printf("a
- b = %d\n", a - b); // subtraction
printf("a
* b = %d\n", a * b); // multiplication
printf("a
/ b = %d\n", a / b); // division
printf("a % b = %d\n", a % b); //modulus
printf("+a
= %d\n", +a); //unary plus
printf("-a
= %d\n", -a); // unary minus
printf("a++
= %d\n", a++); // increment
printf("a--
= %d\n", a--); // decrement
return 0;
}
Output
a + b = 30
a - b = 20
a * b = 125
a / b = 5
a % b = 0
+a = 25
-a = -25
a++ = 25
a-- = 26
For knowing pre and post increment and decrement click here.
0 Comments
Post a Comment