# Compound Interest Program in C In this article, we will learn what is compound interest, what is the formula to calculate compound interest, the algorithm of compound interest, and how to write a compound interest program in c.

## What is compound interest?

In simple word compound interest is “interest on interest”. In other words, an addition to the principal sum of the debt or loan is called compound interest. When a person invests the interest in the principal amount for the next term rather than paying it out so in the next term the person will get interest on the principal amount as well as on the previous interest. For example, if a person gives \$1000 with an interest rate of 5% per year. After one year, the person will have \$1050 After the second year the person have \$1102.5 instead of \$1100 because the person will also get interest of 5% on the previous interest (\$50). After 10 years the person will get a total of \$1628.90 and after 20 years the person will get \$2653.30.

## What is the formula to calculate compound interest?

To calculate the amount of interest given by:

Amount of interest = P(1+R/100)t
P = Principal amount
R = Rate of interest
T = The Time span

Compound Interest = Amount – P

## Algorithm to write compound interest program in c:

Step 1: Define variables principal_amount, rate, time, amount, and compound_interest.

Step 2: Take the input principal amount and store it in the principal_amount variable.

Step 3: Take the input rate and store it in the rate variable.

Step 4: Take the input time and store it in the time variable.

Step 5: Calculate the amount using the above formula and store it in the amount variable.

Step 6: Calculate the compound interest using the “Compound Interest = Amount – P” formula and store it in the compound_interest variable.

Step 8: Exit the program.

## Annually compound interest program in c:

We can find annually compound interest using the formula P(1+R/100)t . Let’s see how to write an annually compound interest program in c.

```// compound interest program in c
#include <stdio.h>
#include <math.h>

int main() {
double principal_amount, rate, time_duration, amount, compound_interest;

printf("Enter the principal amount: ");
scanf("%lf",&principal_amount);
printf("Enter the rate of interest: ");
scanf("%lf",&rate);
printf("Enter the time duration: ");
scanf("%lf",&time_duration);

amount = principal_amount*((pow((1+rate/100),time_duration)));

compound_interest = amount - principal_amount;

printf(" The compound interest is: %lf",compound_interest);
return 0;
}```

Output

``````Enter the principal amount: 1000
Enter the rate of interest: 5
Enter the time duration: 2
The compound interest is: 102.500000``````

In the above program, we have defined variables principal_amount, rate, time_duration, amount, and compound interest. First, we take input from the user for the principal amount, rate, and time duration. After that, we will calculate the amount using the above formula. Once we have calculated the amount after that, we will get a compound by subtracting the principal amount from the amount. In the output, we can see that the principal amount is 1000, the rate of interest is 5 and the time duration is 2 so we will get the compound interest of 102.50.

## Half-yearly compound interest program in c and Quarterly compound interest program in c:

In the half-yearly compound interest, the interest is counted as a half year every time. While in the quarterly compound interest, the interest is counted as a ¼ year every time. Let’s see the formula to find compound interest half-yearly and the formula to find compound interest quarterly.

The formula of the half-yearly compound interest: P(1+(R/2)/100)2n

The formula of the quarterly compound interest: P(1+(R/4)/100)4n

Let’s see how to write half-yearly compound interest program in c and how to write quarterly compound interest program in c.

```// half-yearly compound interest program in c and
// quarterly compound interest program in c
#include <stdio.h>
#include <math.h>

int main() {
double principal_amount, rate, time_duration, half_yearly_amount, quarterly_amount, half_yearly_compound_interest, quarterly_compound_interest;

printf("Enter the principal amount: ");
scanf("%lf",&principal_amount);
printf("Enter the rate of interest: ");
scanf("%lf",&rate);
printf("Enter the time duration: ");
scanf("%lf",&time_duration);

half_yearly_amount = principal_amount*((pow((1+(rate/2)/100),2*time_duration)));

half_yearly_compound_interest = half_yearly_amount - principal_amount;

printf(" The half-yearly compound interest is: %lf",half_yearly_compound_interest);

quarterly_amount = principal_amount*((pow((1+(rate/4)/100),4*time_duration)));

quarterly_compound_interest = quarterly_amount - principal_amount;

printf(" \nThe quarterly compound interest is: %lf",quarterly_compound_interest);

return 0;
}```

Output

``````Enter the principal amount: 1000
Enter the rate of interest: 5
Enter the time duration: 2
The half-yearly compound interest is: 103.812891
The quarterly compound interest is: 104.486101``````

In the above program, we have defined variables principal_amount, rate, time_duration, half_yearly_amount, quarterly_amonut, half_yearly_compound_interest, and quarterly_compound_interest. First, we take input from the user for the principal amount, rate, and time duration. After that, we will calculate the amount of half-yearly compound interest using the formula of the half-yearly compound interest. Once we have calculated the half_yearly amount after that, we will get a half-yearly compound by subtracting the principal amount from the half-yearly amount. After that, we will calculate the amount of quarterly compound interest using the formula of the quarterly compound interest. Once we have calculated the quarterly amount after that, we will get a quarterly compound by subtracting the principal amount from the quarterly amount. In the output, we can see that the principal amount is 1000, the rate of interest is 5 and the time duration is 2 so we will get the half-yearly compound interest of 103.81 and quarterly compound interest of 104.48.

Other C Programs