#B3797. Printing Annuity Present Value Factor Table

    ID: 11454 Type: Default 1000ms 256MiB

Printing Annuity Present Value Factor Table

Printing Annuity Present Value Factor Table

In financial computations, the Present Value Interest Factor for an Annuity (PVIFA) is defined as (\mathrm{PVIFA}(i,n)=\frac{1-(1+i)^{-n}}{i}) where (i) is the interest rate per period (in decimal) and (n) is the number of periods. Although the financial meaning is not important here, your task is to help by printing a lookup table for PVIFA values.

The table should be formatted in such a way that the vertical axis (rows) represents the number of periods, and the horizontal axis (columns) represents different interest rates (displayed as percentages). The first row of the output should be a header containing the interest rates (with a '%' sign) right-aligned in a fixed width. Each subsequent row begins with the period number (also right-aligned) followed by the computed PVIFA value for that period and for each interest rate.

The PVIFA for a given period (i) and interest rate (j%) is computed using the formula: [ PVIFA(i, j) = \frac{1-(1+\frac{j}{100})^{-i}}{\frac{j}{100}} ]

Each number (both period numbers and computed values) should be printed using a fixed-width of 7 characters. The computed values must be rounded and formatted to 4 decimal places.

inputFormat

The input consists of two integers separated by spaces. The first integer (r) denotes the number of periods (i.e. the number of rows in the table) and the second integer (c) denotes the number of interest rates (i.e. the number of columns). The interest rates are taken as (1%), (2%), ..., up to (c%).

outputFormat

Print a table with (r+1) lines. The first line is a header that starts with 7 spaces followed by each interest rate formatted as a percentage (with a '%' symbol) in a field of width 7. For each subsequent line representing period (i) (from 1 to (r)), first print the period number in a field of width 7, then for each interest rate from 1% to (c%) compute and print the corresponding (PVIFA) value using the formula, formatted as a floating-point number with 4 decimal places in a field of width 7.

sample

2 3
       1%     2%     3%
  1 0.9901 0.9804 0.9709
  2 1.9704 1.9416 1.9134</code></pre>