7.5. Exercises
Write the loop code necessary to calculate the factorial of a number. For example, 5 factorial is written like this:
5! = 5 * 4 * 3 * 2 * 1 5! = 120
You may assume that a variable named num is defined to hold the number to factor, and that a variable named i is used to control the loop.
Even though the solution shown for Exercise 1 produces correct answers, it has two hiccups in it. Can you determine what they are?
Given that one ounce equals 28.3495231 grams, write a loop that produces a table in a listbox that shows the conversion into grams for weights from one ounce through four pounds.
Look at the solution code for Exercise 3. Can you find a minor change that improves the code?
Assuming that a monetary asset grows by x percent each year, calculate how much the asset is worth at the end of n years (using simple interest).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access