C Program to Calculate Compound Interest

C Program to Calculate Compound Interest

This is C program to calculate compound interest. It is based on basic input output functions, scanf and printf.

Formula to calculate interest is CI=P((1+r/n)^(nt))

#include<stdio.h>
#include<conio.h>
main()
{

//CI=P((1+r/n)^(nt))
float compoundInterest,principal,rate,time; int n;
printf("Enter Principal\n");
scanf("%f",&principal);

printf("Enter rate in percentage\n");
scanf("%f",&rate);

printf("Enter time in years(demcimals)\n");
scanf("%f",&time);

printf("Enter number of times interest is compounded per year\n");
scanf("%d",&n);

compoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time))));
printf("Compound Interest is %f\n",compoundInterest);

}
Formula for CI:
CI=Principal((1+rate/n)^(n*time))
  1. We used
    • principal → To store principal in Rupees
    • rate → To store rate in %
    • time → To store time in years
    • To store number of times interest is compoundedper year
    • compoundInterest → To store output
  2. printf("Enter Principal\n");
      scanf("%f",&principal);
      printf("Enter rate in percentage\n");
      scanf("%f",&rate);
      printf("Enter time in years(demcimals)\n");
      scanf("%f",&time);
      printf("Enter number of times interest is compounded per year\n");
      scanf("%d",&n);

    Taking all the required variables as input from user

  3. compoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time))));
    printf("Compound Interest is %f\n",compoundInterest);