This blog is under construction

Sunday 7 July 2013

C program to calculate compound interest

Write a C program to calculate compound interest.


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

  int main() {
        float principal, rate, amount, CI;
        int n;
        /*
         * get the values for principal,
         * rate, period from user
         */
        printf("Enter the value for principal:");
        scanf("%f", &principal);
        printf("Enter the value for rate:");
        scanf("%f", &rate);
        printf("Enter the value of n:");
        scanf("%d", &n);

        /* calculate the total amount */
        amount = principal * pow((1 + rate/100), n);

        /* find the compound interest */
        CI = amount - principal;

        /* print the result */
        printf("Compound Interest is %f\n", CI);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the value for principal:1000
  Enter the value for rate:10
  Enter the value of n:2
  Compound Interest is 210.00





See Also:

1 comment:

  1. C programming is not a simple computer language, which could be learnt by anyone at any time. Thanks for this program.

    ReplyDelete