Chapter 1 Programming Concepts
|1)||Create the following structure: Based on the value of a number, determine if it is even or odd. Hint: Before you decide how to define even and odd numbers, you should decide what structure must be used to achieve the desired results.|
Answer: Your answer should look similar to the following:
IF MOD(NUMBER, 2) = 0 DISPLAY 'THIS NUMBER IS EVEN' IF MOD(NUMBER, 2) != 0 DISPLAY 'THIS NUMBER IS ODD'
In this example, you are using the selection structure because a decision whether a number is even or odd must be made. This decision can be made with the help of the built-in function MOD. This function returns the remainder of the NUMBER divided by 2. If a number is divisible by 2 (in other words, there is no remainder), ...