Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Simple Interest Formula
3.
Basic Terminology
4.
How is simple interest calculated?
4.1.
Example
5.
Algorithm to Calculate Simple Interest Program in C
6.
C Program to calculate simple interest
6.1.
Code
6.2.
C
6.3.
Explanation of code
6.4.
Time and Space Complexity
7.
Frequently Added Questions
7.1.
What is a simple interest model?
7.2.
What is principal in simple interest?
7.3.
Where is simple interest used?
7.4.
How do we calculate compound interest?
7.5.
How compound interest rate is different from simple interest?
8.
Conclusion
Last Updated: Jun 21, 2024
Easy

Program to calculate the simple interest in C

Author Nikhil Joshi
2 upvotes
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Simple interest is a quickest method of calculating the interest on loan. Here, we'll explore how to calculate simple interest using the C programming language.

Simple interest program in C

Interest is the extra amount paid over the principal amount when we borrow money. In this article titled “Simple Interest Program in C”, we will discuss the logic and algorithm behind the simple interest program in c.

Simple Interest Formula

The formula for calculating simple interest (SI) is:

Simple Interest = (P * R * T) / 100

where:

  • P is the principal amount (initial amount of money).
  • R is the rate of interest per year (as a percentage).
  • T is the time duration for which the money is borrowed or invested (in years).

This formula gives the amount of interest earned or paid on the principal amount over a specified time period, assuming the interest is calculated based on the original principal only.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Basic Terminology

Before looking at how to write a simple interest program in c, let’s discuss some terminology related to simple interest.

  1. Principal amount: It is the amount that the borrower had originally borrowed. 
  2. Interest: It is the percentage of the principal amount charged extra. An Interest rate is set before lending the principal amount.
  3. Time: It is the duration for which money is lent.

How is simple interest calculated?

Let’s say is the principal amount, is the interest rate, and T is the time for which money is lent. Then the interest will be calculated using the following formula:

Simple Interest = (P * R * T) / 100

simple interest formula

We multiply the principal amount by the interest rate and time to calculate the interest.  

Example

Ques. Calculate the simple interest on a loan amount of Rs. 4016.25 at 9% per annum in 5 years. Find the total amount of money the borrower had to pay.

Ans. The total amount of money the borrower had to pay = Principal amount + Interest on Principal amount.

Now, Interest = (P * T * R) / 100

So, Interest = Rs (4016.25 * 9 * 5)/100 = Rs 1807.3125.

Total money to pay back = 4016.25 + 1807.3125 = Rs 5823.5625 ~ Rs 5823.6

Algorithm to Calculate Simple Interest Program in C

We can make a simple interest program in c using the following steps:

  1.  First, store the principal amount (P), rate of interest ®, and time(T) in the appropriate data type. Generally, all these values can be stored in double data type because their domain includes decimal values.
  2. Calculate Interest using the formula I = (P x R x T) / 100. Interest can also be stored in double data type.
  3. The calculated value can be printed or used in the program.

C Program to calculate simple interest

Code

  • C

C

// Simple Interest Program in C
#include <stdio.h>

int main() {
  
   double P = 20000.0; // principal amount
   double R = 7.5; // 7.5 % interest rate
   double T = 4; // For 4 years
  
   double interest = ( P * R * T ) / 100 ;
   printf("interest is %0.2f ", interest);
  
   return 0;
}

 

Output

interest is 6000.00

Explanation of code

  1. We will first declare three variables, P, R and T. These variable stores principal amount, interest rate and time for lending, respectively.
  2. Then, interest is calculated using the formula Interest = (P*R*T)/100.
  3. The interest is printed using the printf function. “%0.2f” denotes that we are printing a float/decimal value and need numbers only up to two decimal places.  

Time and Space Complexity

Simple Interest program in c only requires assignment and multiplication operations. These operations require constant time, and also they are constant in number. Hence, the time complexity is O(1).

Similarly, we only need a constant no. of variables and hence space complexity is also O(1).

Also see, Short int in C Programming

Frequently Added Questions

What is a simple interest model?

A simple interest model is a financial calculation method where interest is earned or paid only on the initial principal amount without considering reinvestment or compounding.

What is principal in simple interest?

The principal in simple interest is the initial amount of money deposited or borrowed on which interest is calculated, without considering additional contributions or compounding.

Where is simple interest used?

Simple interest is used in finance to calculate interest on a principal amount, often for loans, savings accounts, or investments, where interest accrues linearly over time.

How do we calculate compound interest?

The compound interest formula is A = P ( 1 + r / n )nt. 

Here A is the total amount after interest, P is the principal amount, r is the interest rate, n is the number of times interest gets compounded during the time period, and t is the number of periods money is invested.

How compound interest rate is different from simple interest?

We calculate simple interest on the principal or loan amount, whereas compound interest is calculated on the sum of interest accumulated and the principal amount.

Conclusion

Money lending and Interest is an old phenomenon in human history. We can calculate simple interest using the formula I = (P*R*T)/100. When programming in c, we must store variables in the appropriate data type, i.e. double. The time and space complexity of the simple interest program in c is O(1).

Click here to learn more about Simple and Compound Interests.

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enrol in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Happy Learning!

Previous article
Write a Program to Find the Area of a Triangle
Next article
C Program to Reverse a Number
Live masterclass