Some thoughts and reminders about Arithmetic operations

While writing programs, consider following aspects of arithmetic operations.

  1. Addition is commutative, While subtraction is not.  That is a+b = b+a
  2. Subtraction of b from a results different as compared to subtraction of a from b. That is a - b b - a
  3. Multiplication is commutative, while Division is not.
  4. Dividing a by b is different from dividing b by a.
  5. The two types of divisions are integer division and modulus division, results different. Integer divisions result Quotient, modulus division (aka., Mod) results the Remainder
  6. In C/C++, the operator symbol for integer division is / (forward slash) and for modulus division is % (percent sign).
  7. Unlike mathematics, in programming, only parenthesis are used for specifying priority of operators (or order of evaluation).

Activity 1:

Write a program that perform subtraction of two or more numbers, specified by its user. The values to be operated may either be integer (whole numbers) or real numbers (fractional values).

********

Activity 2: 

Write a program that check the commutative property for arithmetic operators. 



Links / references:



Comments

Popular posts from this blog

Preprocessor Directive: "#include"