| |
- 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.
- Write a program to print the numbers from 1 to 50
- Modify the last program so that it also prints the sum of the numbers at the end.
- 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).
- 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..."
- Ask the user for 5 numbers (by using a for loop) and tell them the product of those numbers.
- Ask the user for 5 numbers (by using a for loop) and tell which of those numbers is largest.
- Print those numbers from 1 to 50 that are divisible by 2. Do this in two different ways:
- With a loop that only "touches" every other number.
- With a loop that "touches" every number, but only prints the even ones.
- Print (in order) those numbers from 1 to 50 that are divisible by 2 or divisible by 3.
- 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).
- This is your first cool program Ask the user for a number and tell them whether it is prime.
- 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.
- Further modify the last program so that at the end it prints the average of the students'
average grades.
- 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.
|