Arithmatic Operator in C
0 225
Arithmetic operators in C are used to perform mathematical calculations on operands.
The main arithmetic operators are:
1Addition (+)
2Subtraction (-)
3Multiplication (*)
4Division (/)
5Modulus (%)
1 Addition (+)
The addition operator (+) is used to add two operands.
Syntax:
result = operand1 + operand2;Example:
// program for addition operator in C #include<stdio.h>int main() { int a = 5, b = 3; int result = a + b; printf("Addition of %d and %d is: %d\n", a, b, result); return 0; }
Output:
Addition of 5 and 3 is: 8
2Subtraction (-)
The subtraction operator (-) subtracts the right operand from the left operand.
Syntax:
result = operand1 - operand2;
Example:
// program for subtraction in C #include<stdio.h>int main() { int a = 10, b = 4; int result = a - b; printf("Subtraction of %d and %d is: %d\n", a, b, result); return 0; }
Output:
Subtraction of 10 and 4 is: 6
3Multiplication (*)
The multiplication operator (*) multiplies two operands.
Syntax:
result = operand1 * operand2;
Example:
// program for multiplication in C #include<stdio.h>int main() { int a = 6, b = 7; int result = a * b; printf("Multiplication of %d and %d is: %d\n", a, b, result); return 0; }
Output:
Multiplication of 6 and 7 is: 42
4Division (/)
The division operator (/) divides the left operand by the right operand.
Syntax:
result = operand1 / operand2;Example:
// program for division in C #include<stdio.h>int main() { int a = 20, b = 5; int result = a / b; printf("Division of %d by %d is: %d\n", a, b, result); return 0; }
Output:
Division of 20 by 5 is: 4
5Modulus (%)
The modulus operator (%) returns the remainder when the left operand is divided by the right operand.
Syntax:
result = operand1 % operand2;
Example:
// progam for modulus in C #include<stdio.h.int main() { int a = 10, b = 3; int result = a % b; printf("Modulus of %d by %d is: %d\n", a, b, result); return 0; }
Output:
Modulus of 10 by 3 is: 1
Share:
Comments
Waiting for your comments