Midterm #1 V22.0101
October 27, 1997 Samuel Marateck

1. (25 points.) Given the procedure heading procedure random_digits( n : integer; var ran : longint); where n indicates the number of digits in an integer to be produced, write the rest of random_digits such that the procedure produces a random integer ran where each digit is a random digit. So if n is 3, the procedure would produce a number like 241, where 2, 4, and 1 are all random digits.

2. (25 points) Given the procedure heading procedure how_many_digits( number : longint; var n : integer); write the body of the procedure such that it determines how many digits n are in number?

3. (25 points) Given the procedure heading procedure print( number : longint; n : integer); where n is the number of digits in number, write the rest of the procedure such that it prints each digit of the integer, starting from the left-most digit, on a new line. For example, if the value of number is 4338, the procedure would print:

4
3
3
8

4. (25 points) Write a program fragment that multilpies the numbers on all the lines of a group of lines that ends with ^Z ( an end of file). For instance if the group of lines is:

1 2 3
4
5 5
the product would be 600.



Sam Marateck
Mon Oct 27 23:57:02 EST 1997