C Program for the compound interest?

Compound interest is the interest calculated on both the principal amount and the previously earned interest. Unlike simple interest, compound interest grows exponentially because the interest earned in each period is added to the principal for the next calculation period.

Syntax

Compound Interest = Principal * pow((1 + Rate/100), Time) - Principal
Amount = Principal * pow((1 + Rate/100), Time)

Example: Calculate Compound Interest

Here's a complete C program to calculate compound interest using the mathematical formula −

#include <stdio.h>
#include <math.h>

int main() {
    float principal, rate, time, amount, compound_interest;
    
    /* Initialize values */
    principal = 5000;
    rate = 4;
    time = 5;
    
    /* Calculate amount using compound interest formula */
    amount = principal * pow((1 + rate / 100), time);
    
    /* Calculate compound interest */
    compound_interest = amount - principal;
    
    printf("Principal: %.2f
", principal); printf("Rate: %.2f%%
", rate); printf("Time: %.0f years
", time); printf("Amount: %.2f
", amount); printf("Compound Interest: %.2f
", compound_interest); return 0; }
Principal: 5000.00
Rate: 4.00%
Time: 5 years
Amount: 6083.26
Compound Interest: 1083.26

Example: Interactive Input

Here's a version that accepts user input for principal, rate, and time −

#include <stdio.h>
#include <math.h>

int main() {
    float principal, rate, time, amount, compound_interest;
    
    printf("Enter principal amount: ");
    scanf("%f", &principal);
    
    printf("Enter annual interest rate (in %%): ");
    scanf("%f", &rate);
    
    printf("Enter time period (in years): ");
    scanf("%f", &time);
    
    /* Calculate compound interest */
    amount = principal * pow((1 + rate / 100), time);
    compound_interest = amount - principal;
    
    printf("
--- Compound Interest Calculation ---
"); printf("Principal Amount: $%.2f
", principal); printf("Interest Rate: %.2f%% per annum
", rate); printf("Time Period: %.1f years
", time); printf("Final Amount: $%.2f
", amount); printf("Compound Interest Earned: $%.2f
", compound_interest); return 0; }
Enter principal amount: 10000
Enter annual interest rate (in %): 5
Enter time period (in years): 3

--- Compound Interest Calculation ---
Principal Amount: $10000.00
Interest Rate: 5.00% per annum
Time Period: 3.0 years
Final Amount: $11576.25
Compound Interest Earned: $1576.25

Key Points

  • The pow() function from math.h is used to calculate the power operation
  • Compound interest formula: CI = P × (1 + r/100)^t - P
  • The final amount includes both principal and compound interest

Conclusion

Compound interest calculations in C use the pow() function to handle exponential growth. This mathematical approach provides accurate results for financial calculations and demonstrates the power of compounding over time.

Updated on: 2026-03-15T11:35:43+05:30

299 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements