- 1C Hello World Program
- 2C Program to Print Your Own Name
- 3C Program to Print an Integer Entered by the User
- 4C Program to Add Two Numbers
- 5C Program to Multiply Two Floating‑Point Numbers
- 6C Program to Print the ASCII Value of a Character
- 7C Program to Swap Two Numbers
- 8C Program to Calculate Fahrenheit to Celsius
- 9C Program to Find the Size of int, float, double and char
- 10C Program - Add Two Complex Numbers
- 11C Program - Find Simple Interest
- 12C Program - Find Compound Interest
- 13C Program - Area And Perimeter Of Rectangle
- 14C Program - Check Whether a Number is Positive, Negative, or Zero
- 15C Program - Check Whether Number is Even or Odd
- 16C Program - Check Whether a Character is Vowel or Consonant
- 17C Program - Find Largest Number Among Three Numbers
- 18C Program - Calculate Sum of Natural Numbers
- 19C Program - Print Alphabets From A to Z Using Loop
- 20C Program - Make a Simple Calculator
- 21C Program - Generate Multiplication Table
- 22C Program - Reverse a Number
- 23C Program - Check whether the input number is a Neon Number
- 24C Program - Find All Factors of a Natural Number
C Program – Find Compound Interest - Using pow() & Loop
Compound Interest Using pow()
#include <stdio.h>
#include <math.h>
int main() {
double principal, rate, time, amount, interest;
printf("Enter principal amount: ");
scanf("%lf", &principal);
printf("Enter annual interest rate (in %%): ");
scanf("%lf", &rate);
printf("Enter time (in years): ");
scanf("%lf", &time);
amount = principal * pow((1 + rate/100), time);
interest = amount - principal;
printf("Amount = %.2lf\n", amount);
printf("Compound Interest = %.2lf\n", interest);
return 0;
}
Enter principal amount: 1000
Enter annual interest rate (in %): 5
Enter time (in years): 2
Amount = 1102.50
Compound Interest = 102.50
The compound interest formula calculates the accumulated amount by raising (1 + rate/100) to the power of the number of years and multiplying it by the principal. Subtracting the original principal yields the interest earned.
Compound Interest Using a Loop
#include <stdio.h>
int main() {
double principal, rate, time, amount;
int i;
printf("Enter principal amount: ");
scanf("%lf", &principal);
printf("Enter annual interest rate (in %%): ");
scanf("%lf", &rate);
printf("Enter time (in years): ");
scanf("%lf", &time);
amount = principal;
for (i = 1; i <= time; i++) {
amount = amount + (amount * rate / 100);
}
printf("Amount = %.2lf\n", amount);
printf("Compound Interest = %.2lf\n", amount - principal);
return 0;
}
Enter principal amount: 2000
Enter annual interest rate (in %): 3
Enter time (in years): 3
Amount = 2185.45
Compound Interest = 185.45
Instead of using pow(), this method iteratively updates the amount each year by adding the interest earned in that period. After all periods, the difference between the final amount and the principal gives the compound interest.
⬅ Previous TopicC Program - Find Simple Interest
Next Topic ⮕C Program - Area And Perimeter Of Rectangle
Next Topic ⮕C Program - Area And Perimeter Of Rectangle
Comments
Loading comments...