#include <stdio.h>
#include <conio.h>
#include <math.h>
Void main()
{
float principal, rate, time,
compoundInterest;
clrscr();
printf("Enter principal
amount: ");
scanf("%f",
&principal);
printf("Enter rate of
interest: ");
scanf("%f",
&rate);
printf("Enter time
period (in years): ");
scanf("%f", &time);
// Calculate compound
interest
compoundInterest = principal
* pow(1 + (rate / 100), time) - principal;
printf("Compound
Interest = %.2lf\n", compoundInterest);
getch();
}
Output:--
Enter principal amount: 1000
Enter rate of interest: 2
Enter time period (in years): 3
Compound Interest = 61.21
This C program calculates compound interest using the following formula:
Compound Interest = Principal * (1 + (Rate / 100))^Time - Principal
Here's a breakdown of the code:
Include necessary headers:
stdio.h
for input/output operations.math.h
for thepow
function to calculate the power.
Declare variables:
principal
: Stores the principal amount.rate
: Stores the rate of interest.time
: Stores the time period in years.compoundInterest
: Stores the calculated compound interest.
Get user input:
- Prompt the user to enter the principal amount, rate of interest, and time period.
- Use
scanf
to read the values from the user.
Calculate compound interest:
- Use the formula
compoundInterest = principal * pow(1 + (rate / 100), time) - principal
to calculate the compound interest. - The
pow
function is used to calculate the power of the expression(1 + (rate / 100))
.
- Use the formula
Print the result:
- Print the calculated compound interest using
printf
.
- Print the calculated compound interest using
Return 0:
- Indicate successful program execution.
No comments:
Post a Comment