Operators are the special symbols in the C programming language, which is used to perform various mathematical and logical operations on the given operands to return the appropriate results. There are various operators in the C programming language such as Arithmetic Operators, Relational Operators, Shift Operators, Logical Operators, Bitwise Operators, Ternary or Conditional Operators, and Assignment Operators. But here, we will understand only the Arithmetic Operator in the C programming language.
Types of Arithmetic Operators in C
The C Arithmetic Operators are of two types based on the number of operands they work. These are as follows:
- Binary Arithmetic Operators
- Unary Arithmetic Operators
1. Binary Arithmetic Operators in C
The C binary arithmetic operators operate or work on two operands. C provides 5 Binary Arithmetic Operators for performing arithmetic functions which are as follows:
Operator |
Name of the Operator |
Arithmetic Operation |
Syntax |
---|---|---|---|
+ |
Addition |
Add two operands. |
x + y |
– |
Subtraction |
Subtract the second operand from the first operand. |
x – y |
* |
Multiplication |
Multiply two operands. |
x * y |
/ |
Division |
Divide the first operand by the second operand. |
x / y |
% |
Calculate the remainder when the first operand is divided by the second operand. |
x % y |
Example of Binary Arithmetic Operator in C
#include
int main()
{
int num1, num2;
int sum, diff, multiply, mod;
float div;
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
sum = num1 + num2;
diff = num1 - num2;
multiply = num1 * num2;
div = (float)num1 / num2;
mod = num1 % num2;
printf("SUM = %d\n", sum);
printf("DIFFERENCE = %d\n", diff);
printf("PRODUCT = %d\n", multiply);
printf("QUOTIENT = %f\n", div);
printf("MODULUS = %d", mod);
return 0;
}