Operators that are used for all the arithmetic operations are listed below.
Operator | Meaning | Description |
---|---|---|
+ | Addition or Binary Plus | This Operator is used for the addition of variables |
– | Subtraction or Binary Minus | Used for Subtraction or variables |
* | Multiplication | Used for Multiplication of Variables |
/ | Division | Used for the division of two variables |
% | Modulo Division (Remainder) | This gives us a result as a remainder. This can not be applied to floating point data |
Examples:
#include <stdio.h>
int main(){
// variable declaration and initialization
int x = 10;
int y = 20;
int z = 21;
int a,s,m,d,r;
// example of addition, subtraction, multiplication, division and modulo
a = x + y;
s = y - x;
m = x * y;
// this is integer division
d = z / y;
r = z % y;
printf("x + y = %d\n", a);
printf("y - x = %d\n", s);
printf("x * y = %d\n", m);
printf("z / y = %d\n", d);
printf("z %% y = %d\n", r); // notice %% to print %
return 0;
}
Expected Output:
x + y = 30
y - x = 10
x * y = 200
z / y = 1
z % y = 1