Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication and division. There are five arithmetic operators available in C (
The table below lists the arithmetic operators+, -, *, /, %
). All arithmetic operators are binary operators, ie; they operate on two operands to produce the result.Operator | Name | Description | Example |
---|---|---|---|
+ | Addition Operator | '+' Operator adds two values. This operator works on integer, float and character variables. | 20 + 10 return 20 |
- | Subtraction Operator | '-' Operator produces a result after subtracting two values. It also works on integer, float, character variables. | 20 - 10 returns 10 |
* | Multiplication Operator | '*' Operator produces result after multiplication of operands. | 20 * 10 returns 200 |
/ | Division Operator | '/' Operator produces result of division of first operand by second. | 20 / 10 returns 2 |
& | Modulus Operator | '%' Operator generates the remainder after integer division. | 25 % 10 returns 5 |
Examples of Arithmetic Operators
- #include <stdio.h>
- int main()
- {
- int a = 25, b = 10;
- printf("Sum: %d\n", a + b);
- printf("Difference: %d\n", a - b);
- printf("Product: %d\n", a * b);
- printf("Quotient: %d\n", a / b);
- printf("Remainder: %d\n", a % b);
- return 0;
- }
- Output:
- Sum: 35
- Difference: 15
- Product: 250
- Quotient: 2
- Remainder: 5
No comments:
Post a Comment