|
Written by Tomasz Lubiński
|
|
Sunday, 13 September 2009 11:31 |
|
Calculation of the absolute value of the given number is the simplest example of using the algorithm with a decision. For a given number x the absolute value |x| is defined as:
- x, if x ≥ 0,
- -x, otherwise.
The operation of calculating the absolute value of x we can present by the following block diagram:

Example: Assume that x is equal to 5. We check decision "if 5 ≥ 0?". Yes - so the result is equal to x, so it is 5. Assume that x is equal to -3, now. We check decision "if -3 ≥ 0?". It is equal to No, so result is equal to -x, so it is - -3, two minuses give us +, so the final result is equal to 3.
|
|
Last Updated on Thursday, 27 May 2010 18:59 |