Be sure to review all the lecture examples, section/lab exercises, and homework problems!
M exercises: You should complete the exercises in Insight labelled M at the end of each section. These exercises are variations on the main example in each section and help make sure that you actually understand the examples.
The income tax code in Timbuktu works as follows: the first $30,000 of income is taxed at 25%, the next $30,000 at 30%, and any amount above $60,000 at 40%. Write a program that accepts as input an income amount and computes and prints the correct tax amount to be paid in Timbuktu.
rem()
are allowed. Assume nBig,nSm > 1. Example output for nBig=6 and nSm=3 is:
6 5 is prime 4 3 is prime
[Tough problem] A mode is the number in a sequence that appears the most number of times. A user is prompted to enter a sequence of non-negative numbers in non-decreasing order one-by-one. The user indicates the end of the sequence by entering a negative number. Write a script to obtain such user input and determine the mode of the sequence. If there are multiple modes, you may report any one of them as the mode. Do not use arrays. Below is an example run:
Determine mode of a set of nonnegative integers. Use a negative number to quit. Give me a number: 70 Another number not smaller than the previous: 71 Another number not smaller than the previous: 80 Another number not smaller than the previous: 80 Another number not smaller than the previous: 80 Another number not smaller than the previous: 91 Another number not smaller than the previous: 93 Another number not smaller than the previous: -1 Mode is 80.