# How to find compound interest in c without using pow function

+1 vote

answered Oct 24, 2021 by (45,000 points)
edited Oct 25, 2021 by Peter Minarik

Let's see if I get you right.

You would like to invest startAmount at a rate of interestRate and you'd like to know how much money you'll have at the end of n investment periods.

In this case, you'd have the following formula: totalMoney = startAmount * (1 + interestRate)n

, where interestRate is expressed as a floating-point number (e.g. 10% --> 0.10)

Now, you ask how you can do this without raising anything to a certain power.

Well, if you take the basic definition of the ab, it means that you multiply a with itself b times.

In programming terms, instead of using the pow() function, you can write a loop that multiplies a given number of times. E.g.:

```float CalculateInterest(float startAmount, float interestRate, size_t n)
{
float multiplier = 1.0 + interestRate;
for (size_t i = 0; i < n; i++)
startAmount *= multiplier;

return startAmount;
}
```

Is this what you're after?