CS100 M Fall 2003
Review/Practice Questions for Prelim 1

Question 1
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.

Question 2
Write a program that accepts three numbers as input and prints the maximum of the three numbers. Do not use arrays. The only MATLAB built-in function allowed is input.

Question 3
Write a program to calculate some statistics of a sequence of non-negative numbers entered one by one and terminated by a negative number. Do not use arrays or MATLAB predefined functions (other than input). The statistics to calculate are sum, mean, maximum, and minimum. Store the statistics in variables and print the values to the screen.

Question 4
Given integers nBig and nSm where nBig > nSm, write a program segment that lists the integers in decreasing order and annotates the integers that are prime numbers. Assume nBig,nSm > 1. Example output for nBig=6 and nSm=3 is
  6
  5 is prime
  4
  3 is prime

Question 5
Scalar bal is the current balance in an account. Each cell in vector dep contains an amount deposited to the account in one day. Given bal and dep, write a program segment to print the daily balance up to and including the day that the balance gets to (or above) 1000.
Built-in function that you may use: length

Question 6
Given a vector v, write a program segment that calculates the cumulative products of the vector. Store the cumulative products in vector cprod. Use a while loop to solve this problem. The only MATLAB built-in function allowed is length. E.g., vector 3 4 1 2 has cumulative products 3 12 12 24. Note that the first element is multiplied by 1.

Question 7
Vectors ptA, ptB, and ptC are vectors of length two, each representing the coordinates of a point. I.e., ptA(1) and ptA(2) are the x-coordinate and y-coordinate, respectively, of point A. Given ptA, ptB, and ptC, write a program segment that calculates the perimeter of the triangle formed by the three points. Note: On an exam you would be given the formula for calculating the distance between two points. For this review question, look up the formula if you do not know it by heart!.

Other review questions from lecture
Have you completed the questions from the 9/23 lecture? If not, do them now!