| |
- 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.
- Ask the user for an integer and tell them whether it is negative or non-negative.
- Tell them, in addition, whether the number is odd or even.
- Ask the user for a second integer and tell them whether it is a multiple of the first,
and, if it is, how many times the first it is.
- Tell the user which number is larger or if they are equal.
- Ask the user for a third integer and tell them whether the three numbers form
a pythagorean triple
(that is, if the sum of the squares of the first two equals the square of the third).
- Write a program which asks the user for their annual income, and tells
them they are poor, comfortable, or stinking rich, depending on whether their
income is less than $20,000, between $20,000 and $50,000,
or greater than $50,000.
- Write a program which asks the user to type a number from 1 to 5 and
responds with the cardinal version of the number
(i.e. 1st, 2nd, 3rd, 4th, 5th) by printing the number they entered and then
using an
if-else-if statement to print the appropriate suffix.
Notice that the last two cases use the same suffix. Try to capture that commonality
in your program by not having separate cases for those two numbers.
Print "out of range" if they enter any value other than 1 through 5.
- Write another program that does the same thing as the last one, but which uses a
switch statement instead of an if statement.
|