C Program for Compound Interest

Compound interest is a fundamental concept in finance, representing the interest on a principal amount that continuously accumulates based on both the initial principal and the accumulated interest from previous periods. Writing a C program to compute compound interest can be immensely beneficial for financial calculations and understanding the concept’s practical implementation in programming. Let’s write a C program that computes compound interest.

C Program for Compound Interest

Understanding Compound Interest

We can calculate Compound interest by using the following formula –



  • ( A ) is the final amount after interest.
  • ( P ) is the principal amount (initial amount).
  • ( r ) is the annual interest rate (expressed as a decimal).
  • ( n ) is the number of times the interest is compounded per year.
  • ( t ) is the time the money is invested for, in years.

Implementation in C Program


c program for compound interest

Explanation of the C Program

  1. The program begins by including the necessary header files (stdio.h for input/output and math.h for mathematical functions like pow()).
  2. A function calculateCompoundInterest() is defined to compute compound interest using the formula provided earlier.
  3. Inside main(), user inputs are taken for principal amount, annual interest rate, time, and compound frequency per year.
  4. The calculateCompoundInterest() the function is called with the provided inputs, and the calculated compound interest is displayed.

Creating a C program to calculate compound interest provides an excellent opportunity to apply mathematical formulas in programming. This program enables users to determine the compound interest accrued on an investment, demonstrating the practical implementation of finance-related concepts in C programming. Understanding and implementing compound interest computation in C can be beneficial for financial analysis, investment planning, and educational purposes.

See Also

Leave a Comment