C Program For Compound Interest

Here’s a C program that calculates the compound interest based on the principal amount, rate of interest, time period, and compounding frequency:

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

int main() {
  // Declare variables
  float principal, rate, time, amount, compound_interest;

  // Get input from user
  printf("Enter principal amount: ");
  scanf("%f", &principal);

  printf("Enter rate of interest: ");
  scanf("%f", &rate);

  printf("Enter time in years: ");
  scanf("%f", &time);

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

  // Calculate compound interest
  compound_interest = amount - principal;

  // Print compound interest
  printf("Compound interest = %f\n", compound_interest);

  return 0;
}

				
			
Output
C Program to Calculate Compound Interest
  • This program first declares five variables: principal, rate, time, amount, and compound_interest. The principal variable stores the principal amount, the rate variable stores the rate of interest, the time variable stores the time in years, the amount variable stores the amount, and the compound_interest variable stores the compound interest.

  • The program then gets input from the user for the principal amount, the rate of interest, and the time in years.

  • The program then calculates the amount using the formula amount = principal * pow((1 + rate / 100), time).

  • The program then calculates the compound interest using the formula compound_interest = amount - principal.

  • The program then prints the compound interest to the console.

  • You can change the values of the variables in the program to calculate compound interest for different amounts, rates, and times.