5. if and for Statements
Note: If the task description says that the program has to read in one natural number, then the program does not have to verify that the input value truly respects that requirement. The task description actually limits what a user is allowed to provide as the input data. Similarly, the program does not need to verify that the input numbers are different if the task description states that they have to be.
- Modify the preceding program so that it now prints out squares of the first 20 natural numbers.
- Write a program that reads in one natural number (let us call it n) and then prints out squares of the first n natural numbers.
- Write a program that reads in two numbers (from standard input) and then writes out the value of the smaller one.
- Write a program that reads in three different numbers and then writes out the value of the smallest one.
- Write a program that reads in one natural number and then writes out a message telling whether the given number has exactly two digits. If you need a hint, see the footnote[*].
- Let us play with corporate taxes. Write a program that reads in two numbers: the annual income and annual expenses of a company, expressed in dollars. The program has to write out the amount of tax that the company has to pay; let us call it the profit tax. If the expenses are greater than the income, then the profit tax equals 0 dollars. Otherwise, let the profit tax be equal to 20% of the profits, where profits equal the difference of income and expenses.