C program to calculate compound interest
In this post, you will learn how to calculate the compound interest using the C programming language.
Compound interest is the addition of interest to the principal sum of a loan or deposit, or in other words, interest on interest. Compound interest makes a sum of money grow at a faster rate than simple interest because in addition to earning returns on the money you invest, you also earn returns on those returns at the end of every compounding period.
Compound Interest Formula
The Compound Interest (C.I.) formula is calculated as -
Compound Interest = P(1 + R/100)r
Where,
P is the principle amount
T is the time and
R is the rate
C program to calculate Compound Interest
In the given C program, we allow users to enter the principal amount, rate of interest, and number of years. By using these values, the program calculates compound interest.
#include <stdio.h>
#include <math.h>
int main()
{
float p, r, t, CI;
// Input principle, time and rate
printf("Enter the principal amount : ");
scanf("%f", &p);
printf("Enter the time span : ");
scanf("%f", &t);
printf("Enter rate of interest : ");
scanf("%f", &r);
// Calculate compound interest
CI = p* (pow((1 + r / 100), t));
printf("Compound Interest = %f", CI);
return 0;
}
Output 1 -
Enter the principal amount : 34000
Enter the time span : 5
Enter rate of interest : 6.5
Compound Interest = 46582.960938
Output 2 -
Enter the principal amount : 42000
Enter the time span : 8
Enter rate of interest : 7.5
Compound Interest = 74906.093750
C program to calculate Compound Interest using function
In the given C program, we define a user function to calculate the compound interest.
#include<stdio.h>
#include<math.h>
float compound_interest(float P, float T, float R) {
return P*(pow(1+(R/100), T));
}
int main() {
float p, t, r;
printf("Enter Principle amount, rate of interest, and time: ");
scanf("%f%f%f", &p, &r, &t);
printf("Interest value: %f", compound_interest(p, t, r));
}
Output of the above code:
Enter Principle amount, rate of interest, and time: 12000 4.7 5
Interest value: 15097.837891
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative