Arithmatic Operator in C
0 931
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:
2Subtraction (-) The subtraction operator (-) subtracts the right operand from the left operand. Syntax:
3Multiplication (*) The multiplication operator (*) multiplies two operands. Syntax:
4Division (/) The division operator (/) divides the left operand by the right operand. Syntax:
5Modulus (%) The modulus operator (%) returns the remainder when the left operand is divided by the right operand. Syntax:
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>Output: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; }
Addition of 5 and 3 is: 8
2Subtraction (-) The subtraction operator (-) subtracts the right operand from the left operand. Syntax:
Example:
result = operand1 - operand2;
// program for subtraction in C #include<stdio.h>Output: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; }
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>Output: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; }
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>Output: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; }
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.Output: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; }
Modulus of 10 by 3 is: 1
Share:




Comments
Waiting for your comments