How to Calculate Simple and Compound Interest by C Program

Simple and Compound Interest by C Program

Introduction :

In finance, calculating interest is a very important task. It is used in various financial fields such as banking sector, investments and more. There are two types of interest we can see like simple and compound interest. Using the C programming language, you can calculate the simple and compound interest.

In this article, I shall show you how to calculate the simple and compound interest using C programming language. Here, you have to take the principal amount, rate of interest and the time period from the user.

What is simple interest :

Simple interest is a mathematical method that calculate the interest on a principal amount over a period of time. It is called “simple” because it is very easy to calculate the interest of principal amount. Simple Interest is generally known as S.I.

Simple interest is calculated only on the principal amount. It does not calculate on the interest. It is generally used for short periods such as car loan, short term loan, personal loans, savings account, etc.

Formula of simple interest :

The following formula is used for calculating simple interest.

Simple interest = (principal amount X rate of the interest X time period in year) / 100

What is compound interest :

Compound interest is a mathematical method that calculate the interest on both the principal and the previously earned interest over a period of time. It is very complex to calculate the interest. Compound interest is generally known as C.I.

Compound interest is calculated both on the principal amount and the previously earned interest. It is known as interest on interest. It is generally used for long periods such as savings account, fixed deposit, and loan, mutual funds, bonds etc.

Formula of compound interest :

The following formula is used for calculating compound interest.

Amount= principal(1 + rate/100)time
Compound Interest = Amount – principal

About the program :

This is a C program that calculates the simple and compound interest. When you run the program, it asks you to enter the principal amount, interest rate and time period. Then, the simple and compound interest will be calculated and you can see the result on the console screen.

Explanation of the program :

You have to include stdio.h and math.h library in the program. In the main() function, declare float variables such as “principle”, “amount”, “interest_time”, “interest_rate”, “simple_interest” and “compound_interest”. Using printf() function, ask the user to enter the principal amount, interest rate and time period. You can call scanf() function which takes the inputs from the user and stores them in the variables.

Then, calculate the simple and compound interest of the given principal. You can use pow() function to calculate compound interest. At last, display the result using printf() function on the console screen. In printf() function, I use “%.2f” to format the output to two decimal places.

How run the program :

If you want to run the program on your PC, you have to install VS Code. Then, open the VS Code and create a new file like “simple_compound.c”. After that, copy the following code and paste in the file. Now save the file and run the program to see the output on your PC. You have to know how to setup VS Code for C programming.

Source code of the program :

The following code is the source code of calculating simple and compound interest program in C language.

/*Developed by Puskar Jasu*/
#include <stdio.h>
#include <math.h>
int main()
{
    float principle, amount, interest_time, interest_rate, simple_interest, compound_interest;
    printf("Enter principle of amount\n");
    scanf("%f", &principle);
    printf("Enter rate of interest\n");
    scanf("%f", &interest_rate);
    printf("Enter time period in year\n");
    scanf("%f", &interest_time);
    simple_interest = (principle * interest_time * interest_rate) / 100;
    amount = principle * (pow((1 + interest_rate / 100), interest_time));
    compound_interest = amount - principle;
    printf("The simple interest is %.2f\n", simple_interest);
    printf("The compound interest is %.2f\n", compound_interest);
    return 0;
}

Output of the program :

If you run the program on your PC, you can see the output of the program.

Output of Simple and Compound Interest by C Program

Conclusion :

At last, you have learned how to calculate the simple (S.I.) and compound (C.I.) interest using C programming language. Thank you for visiting my site.

Scroll to Top