Tuesday, January 26, 2016

Arithmetic Operators

Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication and division. There are five arithmetic operators available in C (+, -, *, /, %). All arithmetic operators are binary operators, ie; they operate on two operands to produce the result.
The table below lists the arithmetic operators
OperatorNameDescriptionExample
+Addition Operator'+' Operator adds two values. This operator works on integer, float and character variables.20 + 10return 20
-Subtraction Operator'-' Operator produces a result after subtracting two values. It also works on integer, float, character variables.20 - 10returns 10
*Multiplication Operator'*' Operator produces result after multiplication of operands.20 * 10returns 200
/Division Operator'/' Operator produces result of division of first operand by second.20 / 10returns 2
&Modulus Operator'%' Operator generates the remainder after integer division.25 % 10returns 5

Examples of Arithmetic Operators

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int a = 25, b = 10;
  6. printf("Sum: %d\n", a + b);
  7. printf("Difference: %d\n", a - b);
  8. printf("Product: %d\n", a * b);
  9. printf("Quotient: %d\n", a / b);
  10. printf("Remainder: %d\n", a % b);
  11. return 0;
  12. }
  13.  
  14. Output:
  15. Sum: 35
  16. Difference: 15
  17. Product: 250
  18. Quotient: 2
  19. Remainder: 5

No comments: