Last Updated: June 7, 2026
Two ways money grows when it earns interest. Both start from the same principal, rate, and number of years, but they treat the interest already earned differently.
Simple interest ignores the interest already earned. Every year you earn the same fixed amount, calculated only on the original principal. Start with 1000 at 5 percent and you earn 50 every year, no matter how many years pass.
Compound interest reinvests the interest. At the end of each year, the interest earned is added to the balance, and the next year earns interest on that larger balance. The interest itself earns interest, which is why the formula has an exponent: the balance is multiplied by (1 + rate/100) once per year.
Compute both values from the same inputs and return them together, each rounded to two decimal places.
principal > 0 → There is always a real starting amount, so you never have to handle a zero or negative principal.rate >= 0 → The rate can be zero. When it is, both interests come out to zero, since multiplying by (1 + 0/100) leaves the balance unchanged.time >= 0 (integer years) → Time is a whole number of years. When it is zero, no interest accrues and both values are zero. Because time is an integer, you can compute the compound factor with a plain loop instead of a power function.Simple interest is one flat expression: principal * rate * time / 100, with no loop and no exponent.
Compound interest needs the factor (1 + rate/100)^time. Since time is an integer, you do not need a power function. Start a running product at 1 and multiply by (1 + rate/100) once per year. This keeps the code free of library calls and makes the compounding visible, since each multiplication is one year passing. The compounded balance is principal times that factor, and the interest alone is that balance minus the original principal.
principal * rate * time / 100.factor at 1. Loop time times, multiplying factor by (1 + rate/100) on each pass.principal * factor. Subtract principal to get the compound interest alone.[simpleInterest, compoundInterest].Take principal = 1000, rate = 5, time = 2.
Simple interest is a single calculation: 1000 * 5 * 2 / 100 = 100. Each year earns 50, and over two years that is 100.
For compound interest, start with factor = 1 and multiply by (1 + 5/100) = 1.05 twice, once for each year:
factor = 1.05, balance = 1000 * 1.05 = 1050.factor = 1.05 * 1.05 = 1.1025, balance = 1000 * 1.1025 = 1102.5.The compounded balance is 1102.5, so the compound interest is 1102.5 - 1000 = 102.5. Notice it beats the simple interest by 2.5, which is the interest earned on year one's 50 during year two.
Rounded to two decimals, the answer is: