Next: The while statement Up: Further Structured Design Previous: Review questions

Exercises

  1. In example 2 in this lesson an algorithm was produced to process examination marks. Extend the algorithm so that an indication of pass or fail is printed for each student. A student passes if his/her average mark over the two subjects is greater than 40 and neither mark is below 35. Also extend the algorithm so that it will output a suitable message if no student details are entered.
  2. Design an algorithm to solve the following problem:
    A set of numbers is to be entered to the computer and the number of negative and the number of positive values entered are to be output. All the numbers lie between -100.0 and 100.0.
    Use a sentinel controlled loop and choose a suitable value for the sentinel.
  3. Rewrite your solution to Exercise 1 for the case where the number of students in the class is entered initially. Write one version using a while loop and another using a repeat loop.
  4. Write an algorithm which will print out a table of ascending powers of two from two to the power zero (1) and terminate printing at the greatest value less than 10,000. Give two versions of the algorithm, one using a while loop and the other using a repeat-until loop.



Next: The while statement Up: Further Structured Design Previous: Review questions