In this tutorial you will learn about the c program to calculate simple interest using function and its application with practical example.
In this tutorial, we will learn to create a C program that will Calculate Simple Interest using function in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- C Operators.
- C functions,
- basic input/output.
What Is Simple interest?
Simple interest is basically a calculation of the interest charged on a given principal amount with in a particular part of time by the bank to customer or taken by bank.
Simple Interest = (p * n * r) / 100
here, p = Principal,
n = Time Period or year.
r = Rate of Interest.
Example
Let take an example of this,
p=5000,r=10,and t=1 year.
then,
Output
Algorithm
- Firstly define Principal, rate and Time of loans.
- Apply the formula.
- Output Simple Interest.
C Program to Calculate Simple Interest.
First of all we take principal ,rate and time and pass them to function as a argument that will calculate the simple interest.let see a program for these.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> float Simple_int(float p, float r, float t) // function for finding simple interest { float si; si = (p * r * t)/100; // formula return si; // returning yhe value of si } int main() { float a,b,c; float intrest; printf("\nEnter Prinicpal :\t"); scanf("%f",&a); printf("\nEnter year:\t"); scanf("%f",&b); printf("\nEnter Rate:\t"); scanf("%f",&c); // taking all 3 values p,r and time intrest = Simple_int(a,b,c); // passing value in function printf("\nSimple Interest = %.2f\n", intrest); //output printf("\n"); return 0; } |
Output
In the above program, we have first declared and initialized a set variables required in the program.
- a = for taking value of Principal.
- b = for taking value of rate.
- c= for taking value of time.
- p= for holding value of a.
- r = for holding value of b.
- t= for holding value of c.
- si= calculate simple interest.
This program takes three values of principal,rate and time in a,b,c from user and then passing these value in function Simple_int(a,b,c) as argument the above function after calculating value function returns simple interest.
As shown in above figure. The value return by the function is hold by result variable and with help of result we can print the simple interest using function.