Back to DFS's C Page


OAC Problem Set II

Loops

  1. Write a program that accepts a list of prices from the user and prints out the subtotal, the appropriate (for Ontario) taxes and the total purchase price. The three values must be decimal-point aligned. The number of prices is not known before they are entered by the user.
  2. Write a program that reads an integer n from the user and calculates n! (n factorial).

  3. Calculate the value of pi from the infinite series

    pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...

    Print a table that shows the value of pi approximated by 1 term of this series, by two terms, by three terms, etc., up to twenty terms. The table should consist of two columns, one giving the number of terms used for the calculation and the other giving the value calculated.