Example of C part 45 calculate compound interest

Program :
#include<stdio.h>
#include<math.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);

}
Output:
Enter Principal
5000
Enter rate in percentage
5
Enter time in years(demcimals)
10
Enter number of times interest is compounded per year
12
Compound Interest is 8235.047852
Explanation:
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 compounded per 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);
    compoundInterest is calculated by using formula and is then printed.