Next: Exercises Up: Further Structured Design Previous: Summary

Review questions

  1. What does the following algorithm do?
    set sum to zero.
    set i to 1.
    input n.
    while i is less than or equal to n do
       {
        add i to sum.
        increment i.
       }
    output sum.
    
    What would be output if the value entered for n was 0? What would be the effect of reversing the order of the statements in the loop body on the general result produced by the algorithm?



Next: Exercises Up: Further Structured Design Previous: Summary