C program to calculate compound interest - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, November 23, 2019

C program to calculate compound interest - My CS Tutorial


In this tutorial we will learn how to write a program that find(calculate) and print the compound interest.

C program code


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

//CI=P((1+r/n)^(nt))

float compoundInterest,principal,rate,time;
int n;
  printf("\n Enter Principal\n ");
  scanf("%f",&principal);
  printf("\n Enter rate in percentage\n ");
  scanf("%f",&rate);
  printf("\n Enter time in years(demcimals)\n ");
  scanf("%f",&time);
  printf("\n Enter number of times interest is compounded per year\n ");
  scanf("%d",&n);

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


OUTPUT 1:





OUTPUT 2:






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.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.


Created by-- HARSH CHAUHAN

No comments:

Post a Comment