Lab 05
Version 1

 

  1. For the following sub-problems, start with a program that solves the first problem, then expand it to solve each successive problem. Make the program working for one problem before going on to the next.
    1. Write a program to print the numbers from 1 to 50

    2. Modify the last program so that it also prints the sum of the numbers at the end.

    3. Modify the last program to first ask the user for a number and then to print the sum of the numbers from 1 to that number (but not to print the numbers themselves).

    4. Modify the last number to ask the user for a lower number and an upper number, and to then print the numbers from the lower number to the upper number, and their sum.

    From now on I will no longer bother saying "Write a program to..."

  2. Ask the user for 5 numbers (by using a for loop) and tell them the product of those numbers.

  3. Ask the user for 5 numbers (by using a for loop) and tell which of those numbers is largest.

  4. Print those numbers from 1 to 50 that are divisible by 2. Do this in two different ways:
    1. With a loop that only "touches" every other number.
    2. With a loop that "touches" every number, but only prints the even ones.

  5. Print (in order) those numbers from 1 to 50 that are divisible by 2 or divisible by 3.

  6. Ask the user for a number and tell them all the factors of the number (i.e. the numbers between 1 and the number that the number is divisible by).

  7. This is your first cool program Ask the user for a number and tell them whether it is prime.

  8. Modify the program StudentAverage so that it is possible for each student to have a different number of grades to be averaged. That is, ask for the number of homeworks for each student, rather than just once.

  9. Further modify the last program so that at the end it prints the average of the students' average grades.

  10. Further modify the last program so that at the end it prints the average of all the homework grades. Since each student may have a different number of homeworks, this may not be the same as the average added in the last problem.

Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Sun, Sep 20, 1998 at 1:30:13 PM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_05/lab.html