Last Updated on May 11, 2023 by Prepbytes

In this post, we are going to learn the meaning of compound interest, the formula for calculating it, its algorithm, and how to create a compound interest program in C.

## What is Compound Interest?

Compound interest is just "interest on interest" in plain English. In other terms, compound interest is an increment to the loan or debt’s main amount. When someone invests their interest in the principal for the following term rather than paying it out, they will get interest on both the principal and the prior interest. For instance, suppose someone gave $1000 with a 5% annual interest rate. The guy will have $1050 after a year. Because they will additionally receive interest of 5% on the prior interest ($50), the person will have $1102.5 instead of $1100 after the second year. 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 7:**Print the answer.**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

Interest is always counted as a half-year in the case of a half-yearly compound interest. While interest is always counted as a quarter year in quarterly compound interest. Let’s look at the formulas for calculating quarterly and half-yearly compound interest, respectively.

**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.

## Frequently asked Questions

**Q1. What is the formula for a compound interest program?**

**Ans.** The compound interest formula is ((P*(1+i)^n) – P), where P is the principal, i is the annual interest rate, and n is the number of periods.

**Q2. What is the syntax of simple interest?**

**Ans.** Simple Interest is (P*R*T) / 100. P is the principal amount, R is the interest rate, and T is the entire period of time the interest has accrued on the amount. Decimal or percentage are acceptable units of rate. T is measured in years.

**Q3. What is a principal in compound interest?**

**Ans.** P = principal amount (the initial amount you borrow or deposit) r = annual rate of interest (as a decimal) t = number of years the amount is deposited or borrowed for.

**Q4. How to calculate interest rate?**

**Ans.** Interest is easily calculated as follows: Principal x Interest Rate x Time. where the Principal represents the initial investment. Time is the length of the investment, and the rate is the interest rate that is charged.

C Program for Binary Search

C Program to Add Two Numbers

C Program to Calculate Percentage of 5 Subjects

C Program to Convert Binary Number to Decimal Number

C Program to Convert Celsius to Fahrenheit

C Program to Convert Infix to Postfix

C Program to Find Area of Circle

C Program to Find Roots of Quadratic Equation

C program to Reverse a Linked List

C program to reverse a number

Ascending Order Program in C

Menu Driven Program For All Operations On Doubly Linked List in C

C Program for Armstrong Number

C Program For Merge Sort For Linked Lists

C program for performing Bubble sort on Linked List

Hello World Program in C

Perfect Number Program in C

Leap Year Program in C

Odd Even Program in C

Selection Sort Program in C

Linear Search Program in C

While Loop Program in C

C Program to Swap Two Numbers

Calculator Program in C Language

Simple Interest Program in C