Elementary Division 1993

1. LUNCH AT MAC DUFFY'S
Write a program that asks the user to 
place an order for lunch at Mac Duffy's 
and prints out the bill similar to the one 
shown in the sample run.

Test your program by entering 3 
hamburgers, no fries and 2 soft drinks.  
Run the progam again with the numbers 
(7,2,4).

Sample Run

      LUNCH ORDER
ORDER OF HAMBURGERS:  3
ORDER OF FRENCH FRIES:0
ORDER OF SOFT DRINKS: 2

      LUNCH BILL
ITEM	      COST	NUMBER
HAMBURGERS  $1.15       3
FRENCH FRIES$ .55       0
SOFT DRINK$   .45       2

PLEASE PAY $4.35   THANK YOU !!




2. DEBUGGED
The first time you write a program it 
usually has a bug in it When you try to 
correct the problem and run it again, it 
may still have a bug.

Assume that 7 out of 10 times a 
program is run it has a bug in it. This is 
true on the first run, the second run, and 
as many runs as necessary until the 
program run "bug free."

Write a program that simulates the 
debugging of a program which satisfies 
this condition. Print BUG if a bug is 
found or DEBUGGED if not.

Run the program five times and 
compute the average number of bugs in 
all five runs. (The average is the total 
number of bugs in all five programs 
divided by 5.)

Sample Run

1 BUG  BUG  DEBUGGED !!
2 BUG  BUG  BUG  DEBUGGED !!
3 DEBUGGED !!
4 BUG  BUG  BUG  DEBUGGED !!
5 BUG  BUG  DEBUGGED !!

AVERAGE NUMBER OF BUGS = 2.



3. FACTORIAL CHART
A Factorial Chart from 1 to 5 looks like 
the following:

FACTORIAL CHART FROM 1 TO 5	
1!  =  1
2!  =  1x2
3!  =  1x2x3
4!  =  1x2x3x4
5!  =  1x2x3x4x5

Write a program that will generate a 
FACTORIAL CHART FROM 1 TO N  
for any whole number N between 1 and 
9.  Do not compute the factionals.    

Test your program with N = 5 and 
N = 9.

Sample Run

ENTER A VALUE FOR N: 6

FACTORIAL CHART FROM 1 TO 6
1! = 1
2! = 1x2
3! = 1x2x3
4! = 1x2x3x4
5! = 1x2x3x4x5
6! = 1x2x3x4x5x6



4. ALPHABETICALLY
    SPEAKING
Write a program that accepts a sequence 
of three letters and checks whether they 
are in alphabetical order.  

Test your program with the letters:
B,A, D and E, F, H

Sample Run
ENTER THREE LETTERS: B,A,D

B A D ARE NOT ALPHABETICAL



5. SIMPLE LATIN SQUARES
The square arrangement of whole 
numbers

1  2  3  4  
2  3  4  1  
3  4  1  2 
4  1  2  3 

is called a 4 x 4 LATIN SQUARE 
because each whole numbers 1, 2, 3, 
and 4 appear once and only once in each 
row and column.  There are many ways 
to arrange the numbers and still make a 
LATIN SQUARE.

Of all the 4 x 4 LATIN SQUARES, the 
one above has a simple pattern  We call 
it a SIMPLE 4X4 LATIN SQUARE.

Write a program that will generate a 
similar SIMPLE N x N LATIN 
SQUARE for any whole number N 
between 2 and 9.

Test your program with N = 4 and N = 
9. 

Sample Run
ENTER A WHOLE NUMBER 
BEWTEEN 2 AND 9: 6

  SIMPLE 6X6 LATIN SQUARE

1  2  3  4  5  6
2  3  4  5  6  1
3  4  5  6  1  2
4  5  6  1  2  3
5  6  1  2  3  4
6  1  2  3  4  5





	ICPSC 1983
	Elementary Division Problems	




