| 2026 Fall UT CS104c Midterm #1 |
|---|
| Finished |
Magikarp wants to buy a bond. He knows the bond's coupon rate, the annual interest rate, its face value, and the number of years until it matures. The bond pays one coupon at the end of each year and returns its face value at maturity. Help Magikarp find its current price.
Let $$$c$$$ be the coupon rate as a percentage, $$$r$$$ be the annual interest rate as a percentage, $$$F$$$ be the face value, and $$$n$$$ be the number of years until maturity. The coupon paid each year is $$$F \cdot \frac{c}{100}$$$. The bond's current price is
$$$$$$ P = \frac{F}{\left(1+\frac{r}{100}\right)^n} + \sum_{k=1}^{n} \frac{F \cdot \frac{c}{100}}{\left(1+\frac{r}{100}\right)^k}. $$$$$$
The second term is the present value of all coupon payments. The first term is the present value of the face value returned at maturity.
The first line contains two real numbers $$$c$$$ and $$$r$$$ ($$$0 \le c \le 100$$$, $$$0.01 \le r \le 100$$$) — the coupon rate and the annual interest rate, respectively, given as percentages.
The second line contains two integers $$$F$$$ and $$$n$$$ ($$$1 \le F \le 10^6$$$, $$$1 \le n \le 1000$$$) — the face value of the bond and the number of years until it matures, respectively.
Output the bond's current price. Your answer is accepted if its absolute error is at most $$$10^{-4}$$$.
5.0 5.01000 3
1000.000000000000000
6 41000 3
1055.501820664542720
In the first sample, the annual coupon and interest rates are equal, so the bond's current price equals its face value.
In the second sample, the annual coupon is $$$60$$$. Discounting the three coupons and the $$$1000$$$ face value at $$$4\%$$$ gives $$$1055.5018206645$$$.
Hint: in order to satisfy the above error bound, be sure to print many digits of your answer (at least 8).
For example, if your answer is stored in ans:
| Name |
|---|


