LOOP DESIGN PROBLEMS

Simple loops, Complex loops, and Nested loops

1.  The island of Goomagorab has a lizard population of 3000.  The birthrate is 5.2% and the death rate is 2.7% yearly. (Yearly population increase is computed by the formula:
    Increase = (birth rate - death rate) * population.

    A)      Write a program to determine the number of lizards on the island in seven years. 

    B)     Write a program to determine how many years it will take  until the lizard population reaches 4000.

2. Write a program to compute a student's Cal Poly GPA.   Enter the number of courses, then for each course enter the course units and the grade points earned.    Quality Points are course units times grade points.  Divide total quality points by total units to get GPA.


3.  It's time for the circus to pay its annual bird and animal tax.  The circus owner, however, is a little short on cash and can't quite afford the bill, which is figured at a rate of $5.50 per bird and $7.29 per animal.  To stall the tax collector, the owner sends the circus clown to tell city hall a riddle. "A bird has two feet, and an animal has four. We have 36 creatures in our circus, and 100 feet.  How much tax do we owe?"  Write a program which uses a loop to figure out how many animals and birds are in the circus, and what the tax bill should be.  (Hint: the general approach is to try all possible combinations of birds and animals until the number of feet is 100: 1 bird and 35 animals,  2 birds and 34 animals, etc.)

 

4. A car and a train are both travelling toward a railroad crossing on a collision course.  The train is 1200 feet from the crossing and traveling at a constant speed of 40 feet per second.  The car is 1500 feet away and travelling at 55 feet per second.  Write a program to calculate and print each vehicles distance from the crossing at one second intervals.  If the car gets to the crossing first, print "Made it."  If the train gets to the crossing first, print "Crash".

 

5. Write a program to print a triangle composed of a symbol.  The number of lines in the triangle and the symbol should be entered as input from the keyboard.  E.g., if the input values are 7 and #, the output is as follows:

 

      #

     ###

    #####

   #######

  #########

 ###########

#############

 

 

6. Write a program to find the position of the first and last occurrences of the number 12 in a list of integers.

E.g.: Enter numbers:  3 6 12 4 7 12 9 8

First occurrence: 3

Last occurrence: 6