Some thoughts and reminders about Arithmetic operations
While writing programs, consider following aspects of arithmetic operations.
- Addition is commutative, While subtraction is not. That is a+b = b+a
- Subtraction of b from a results different as compared to subtraction of a from b. That is a - b ≠ b - a
- Multiplication is commutative, while Division is not.
- Dividing a by b is different from dividing b by a.
- The two types of divisions are integer division and modulus division, results different. Integer divisions result Quotient, modulus division (aka., Mod) results the Remainder.
- In C/C++, the operator symbol for integer division is / (forward slash) and for modulus division is % (percent sign).
- 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
Post a Comment