Feb. 25, 1997
Working in small groups, design flowcharts and pseudo-code to solve each of the following problems. The first two problems are used within the problems following them.
A simple if/else will do the trick.
A simple while will do. Your algorithm doesn't have to ``do'' anything with the numbers other than read them in and compare them to zero to determine if it is finished.
This combines the previous two problems. The if/else will go into the body of the while loop.
Here is a hint: At the start, the largest number read is the first number read. Compare the current largest number to the number just read. The larger of them is the new current largest number. To visualize this, play a game where one person gives numbers to the second. When the first person gives a zero to the second person, the second person should say what the largest number given was.
For example, if the input is 42, the output should be 2 3 7.
Think about how you would factor a number like 30. Here is the general idea: see if the number is divisible by 2, then if it is divisible by 3, by 4, by 5, etc. (i.e., use a loop). Within the loop, you will need an if/else. Make sure that your solution works for numbers with repeated factors, such as 12 ().
This problem makes use of the previous one and the second one. One while loop goes inside another.