All pastes #730300 Raw Edit

Dark3Lite

public text v1 · immutable
·published 2007-10-09 02:56 UTC
rendered paste body
In the following Algorithm segments, indicate whether or not the loop will terminate. If it will not, why not? Assume it is all integer variables.

counter <-- 0
total <-- α

DOWHILE counter >= α
       total <-- total + 2

ENDDO

b) total <-- 0
   index <-- 1
   REPEAT
       total <-- total +1
       index <-- index + 1

   UNTIL index = 10

c) counter  <--- 0
   total    <--- 0
 DOWHILE counter < = 10
total <-- total + 2
counter <-- counter + 1
ENDDO 

2. Express the following as a nested IF structure using only simple conditions.

IF a < b AND C != D AND (B > D OR B = D) THEN 

S1        ---Where S1 is a staement.


4. Find the sum of a square in the range of 1 to 12. The output should be displayed in the form of a table which shows the integer vlaue and it's square on the same line. The sum is then to be displayed below a header which says: "Tutorial X: Sum of Squares from 1 to 12". Write your algorithm either using psuedocode or a flowchart.

5. A prime number is an integer greater than 1 that is exactly divisible by only 1 and itself eg. 2, 3 , 5, 7. Write an algorithm to test whether a positive integer (greater than or equal to 2) entered by a user is prime). Display the number entered and the phrase "Is a Prime" or "Is not a prime". State any special arithmetic assumptions you use if any to simplify the testing. Use a flowchart for your algorithm.