Simple interest earned
A saver is told the interest they would earn: principal held for years at a whole-percent annual rate, with no compounding.
- Pay the simple rate: principal × rate × years, in minor units.
- The product is divided by 100 for the percent, rounding down.
- A zero rate, zero principal, or zero years all pay nothing.
SimpleInterest(principal: int, ratePercent: int, years: int) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int SimpleInterest(int principal, int ratePercent, int years) {
}
Worked examples
| Call | Result |
|---|---|
SimpleInterest(1000, 5, 2) | 100 |
SimpleInterest(10000, 10, 5) | 5000 |
SimpleInterest(1234, 5, 3) | 185 |
SimpleInterest(2500, 0, 10) | 0 |
Hint
Multiply all three, divide and round down.
Reference solution in C#
public int SimpleInterest(int principal, int ratePercent, int years) {
return (principal * ratePercent * years) / 100;
}