In this C program, we will learn about how to read principal amount, rate of interest and time from user and calculate compound interest. We will first read Principle amount, rate of interest and time using scanf function. We will use below mentioned formulae to calculate Compound Interest (CI).
Required Knowledge
- Amount = P x (1 + R/100)T
- Compound Interest = Amount - P
C program to calculate compound interest
#include <stdio.h> #include <math.h> int main() { float principle, rate, time, amount, interest; printf("Enter Principle\n"); scanf("%f", &principle); printf("Enter Rate of Interest\n"); scanf("%f", &rate); printf("Enter Time\n"); scanf("%f", &time); /* Calculates Amount */ amount = principle * pow((1 + rate/100), time); /* Calculates Interest */ interest = amount - principle; printf("After %d Years\n", time); printf("Total Amount = %.4f\n", amount); printf("Compound Interest = %.4f", interest); return 0; }Output
Enter Principle 100000 Enter Rate of Interest 9 Enter Time 3 After 3 Years Total Amount = 129502.9141 Compound Interest = 29502.9141Related Topics