C Program to Calculate Compound Interest:

How to write a C program to calculate Compound interest with example code. Before we get into the C program to calculate Compound interest example, let us understand the mathematical formula to calculate Compound interest,

Compound Interest = P(1 + R/100)r
Where,
P is the principal amount
R is the rate
T is the time span

 

Below C program allows the user to enter the “principal amount”, “rate of interest”, and the “number of years”. We will calculate compound interest by using entered values with the help of above mentioned simple compound formula.

#include<stdio.h>
int main()
{
float principalAmt, rateOfInterest, Time_Period, compoundInterest;
printf(“Please enter the Principal Amount : = “);
scanf(“%f”, &principalAmt);
printf(“Please Enter Rate Of Interest : = “);
scanf(“%f”, &rateOfInterest);
printf(“Please Enter the Time Period in Years : = “);
scanf(“%f”, &Time_Period);
compoundInterest = principalAmt * (pow(( 1 + rateOfInterest/100), Time_Period));
compoundInterest = compoundInterest – principalAmt;
printf(“Simple Interest for Principal Amount %.2f is = %.2f\n”, principalAmt, compoundInterest);
return 0;
}

Output:

Please enter the Principal Amount: = 1000
Please Enter Rate Of Interest : = 8.85
Please Enter the Time Period in Years: = 2
Simple Interest for Principal Amount 1000.00 is = 184.83

 

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *