In this post, we will learn **how to calculate compound interest using the C** Programming language.

**Compound Interest** is the interest on a deposit calculated based on both the initial principal and the accumulated interest from previous periods.

Compound Interest = Total amount of principal and interest in future less principal amount at present.

**CI = [Principal * (1 + Rate of Interest)Time Period] – Principal**

We will be using the same formula in our program to calculate the compound interest.

So, without further ado, let’s begin the tutorial.

**C Program To Calculate Compound Interest**

// C Program To Calculate Compound Interest #include <stdio.h> #include <math.h> int main(){ float principal, rate, time, CI, amount; // Asking for Input printf("Enter The Principal Amount: \n"); scanf("%f", &principal); printf("Enter Rate of Interest: \n"); scanf("%f", &rate); printf("Enter Time Period: \n"); scanf("%f", &time); amount = principal * (pow((1 + rate/100), time)); CI = amount - principal; printf("Compound Interest is %.2f", CI); return 0; }

**Output**

```
Enter The Principal Amount:
5000
Enter Rate of Interest:
10
Enter Time Period:
3
Compound Interest is 1655.00
```

**How Does This Program Work ?**

` `** float principal, rate, time, CI, amount;**

In this program, we have declared five float data type variables named as **principal**, **rate**, **time**, **CI** and **amount**.

** // Asking for Input
printf("Enter The Principal Amount: \n");
scanf("%f", &principal);
printf("Enter Rate of Interest: \n");
scanf("%f", &rate);
printf("Enter Time Period: \n");
scanf("%f", &time);**

Then, the user is asked to enter the value of each constraint. For example: the principal amount, rate of interest and time period.

** amount = principal * (pow((1 + rate/100), time));**

Now, we used the above formula to compute the compound interest.

The **pow()** function is used to calculate the power raised to the base value. It is declared in the **math.h** header file.

** CI = amount - principal;
printf("Compound Interest is %.2f", CI);**

Then, we subtract the principal amount from the final amount to get the Compound Interest or **CI**.

Finally, the result is displayed to the screen using **printf() **function. Here, we have used **%.2f** format specifier because we want the result to be shown till **2** decimal places only.

**Conclusion**

I hope after going through this tutorial, you understand **how to calculate compound interest using C** Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.