In this section, you will learn how to read the principle, rate and time from the user and write a C Program to calculate compound interest and the total amount.
TOTAL AMOUNT = P*(1 + R/100)T
COMPOUND INTEREST = TOTAL AMOUNT – P
Program to calculate Compound Interest and total amount
/* C-Program:Calculate Compound interest and total amount */
#include <stdio.h>
#include <math.h>
int main()
{
long int p;
int t;
float r, ci, tamt;
printf("Enter the Principal Amount: ");
scanf("%ld", &p);
printf("Enter the Time (or period): ");
scanf("%d", &t);
printf("Enter the Rate of Interest: ");
scanf("%f", &r);
tamt = p*pow((1+r/100),t);
ci = tamt-p;
printf("\nPrincipal Amount = %ld", p);
printf("\nTime = %d", t);
printf("\nRate of interest =%.2f", r);
printf("\ncompound Int.= %.2f", ci);
printf("\nT. Amount = %.2f", tamt);
return 0;
}
Output :-
Enter the Principal Amount: 15000 Enter the Time (or period): 3 Enter the Rate of Interest: 10 Principal Amount = 15000 Time = 3 Rate of interest =10.00 compound Int.= 4965.00 T. Amount = 19965.00
