Example 33: Calculate Interest

Learn how to calculate interest on the given amount.

Problem

When interest compounds q times per year at an annual rate of r% for n years, the principal p compounds to an amount a as per the following formula:

a=p(1+rq100)nqa=p(1+ \frac{{r}}{q * 100})^{nq}

Write a program that takes the values of p, r, n, and q as input and calculates the corresponding amount a.

Example

Input (p, r, n, q) Output
1000, 7.5, 5, 1 1435.630
15000, 12, 4, 2 23907.711
10000, 3.5, 5, 2 11894.450

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.