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).
Get Beginning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.