Calculate Simple Interest in C Program

        Calculate Simple Interest in C Program

Calculate Simple Interest in C Program

Write a C program to input principle, time and rate (P, T, R) from user and find Simple Interest. How to calculate simple interest in C programming. Logic to find simple interest in C program.

{tocify} $title= {Table of Contents} 

What is ‘Simple Interest’?

Simple interest is a quick method of calculating the interest charge on a loan. Simple interest is determined by multiplying the daily interest rate by the principal by the number of days that elapse between payments.

Overview

This article discusses the simple interest in C and the algorithm to find the simple interest in the C
language.

Write a C program that accepts the principle, rate of interest, and time and calculates simple interest.

Introduction

Simple interest is one of the ways to find out the gain or loss amount of a particular percentage.

  • This article discusses the Simple Interest in the C language.
  • This article also discusses the Algorithm and an example of the simple interest program in C.

Simple Interest formula:

Let's understand the formula to calculate the simple interest in the C language.

Simple interest formula is given by:

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

Where,

P is the principal amount

T is the time and

R is the rate

Examples:

EXAMPLE1:

Input:

       P = 10000

       R = 5

       T = 5

Output:

         2500

We need to find simple interest on

Rs. 10,000 at the rate of 5% for 5

units of time.

EXAMPLE2:

Input:

       P = 3000

       R = 7

       T = 1

Output:

      210

Pictorial Presentation:


Mathematically

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

Where P is the principal amount, R is the rate of the interest, and the T is the total time of interest on the amount The units of rate are decimal or percentage The unit of t is years.

Example

Input

Enter principle: 1200

Enter time: 2

Enter rate: 5.4

Output

Simple Interest = 129.600006

Logic to Calculate Simple Interest

Let's understand the logic of writing the simple interest program in c. For calculating simple interest, we must have the values of principal, rate, and the total time of interest.

To calculate the simple interest, we have to simply multiply all the given values and divide the result by 100. To get accurate, simple interest, we can store the result in the double data type, because the double datatype can store the fractional values as well as the whole values very efficiently.

Algorithm of Calculate Simple interest in C program

Let's understand the algorithm to write the simple interest program in C. Step by step descriptive logic to calculate simple interest.

1.       Program start.

2.       Declaration of variable with their data type.

3.       Input principle amount in some variable say principle.

4.       Input time in some variable say time.

5.       Input rate in some variable say rate.

6.       Find simple interest using formula SI = (principle * time * rate) / 100.

7.       Finally, print the resultant value of SI.

8.       printf( ) called to print value of variable

9.       Program end.

Flowchart of Calculate Simple interest in C program


Pictorial Representation of Flowchart


C Program to Calculate Simple Interest

Let's understand how to calculate the simple interest program in C.

Program 1:


Program Output 1:



Program 2:


Program Output 2:


Explanation:

This program will calculate the value of the SI where the principal, rate and the time is given by the user. So first of all, you have to include the stdio header file using the "include" preceding # which tells that the header file needs to be process before compilation, hence named preprocessor directive. There is also another header file conio.h, which deals with console input/output and this library is used here for getch() function.

Then you have to define the main() function and it has been declared as an integer so by default it returns the integer. Inside the main() function you have to declare floating type variables name 'principle', 'rate', 'interest'; Moreover, you have to take another integer type variable name 'time'. Now, use printf() to display the message: "Enter Principle Amount, Rate %% per Annum and Time". Then the scanf() method is used which will take three values from the user and store it into variables - principal, rate and time.

Then according to the formula of simple interest, the multiplicative value of all three i.e. (principal * rate * time) gets divided with 100.0 and is stored in the variable 'sinterest'.

Then all the four values i.e. principal, rate and time along with the calculated value of simple interest gets displayed using four printf() statements. The getch() reads a single byte character from input and getch() is a proper way to fetch a user inputted character

Program 3:


Program Output 3:


Happy coding 

Time Complexity

The Time Complexity of the simple interest program in C is O(1) because all the operations for calculating the simple interest are constant.

Summary

  •          The formula to find the simple interest in C language is (PRT)/100. The P is the Principal, R is the rate, and the T is the total interval time.
  •          The Decimal representation of the simple interest is the most accurate.
  •          The time complexity of finding the simple interest in the C language is O(1).

 



Post a Comment (0)
Previous Post Next Post