The George Washington University
School of Engineering and Applied Science
Department of Computer Science

CSci 51 -- Introduction to Computing -- Spring 2000
Lab #10
For labs meeting March 30-31, 2000

The purpose of this lab exercise is to give you some experience in working with procedures that have input and output parameters, and with general and WHILE loop forms.

A. Write and test a program that prompts the user for a positive integer N, then displays all the powers of 2 that are not greater than N. Display each value on a separate line. For example, if N = 3000, the program will display

1
2
4
8
16
32
64
128
256
512
1024
2048

This program must have the following characteristics:

  1. Use Robust_Input (programs 7.9 and 7.10) to get the value N robustly from the user.
  2. Use the procedure Double (p. 284) instead of explicitly multiplying a value by 2. Include Double as a local procedure in the main program.
  3. Use a general loop form (LOOP - EXIT - END LOOP) to control the iteration. Do not use a FOR loop!
B. Now change the program to use a WHILE loop instead.