C program to calculate simple interest

C program to calculate simple interest

 C program to calculate simple interest 

Before coding the C program to calculate simple interest, we need little knowledge about the simple interest.

Simple interest is calculated by using SI=(P*T*R)/100 formula

Where, 

SI is a simple interest

P is the principal amount

T is time (In years)

R is the rate of interest 

Note 

This is a comment written inside //. It does not have to be written while programming. The reason for using it is for the convenience and understanding of another programmer

 C program to calculate simple interest (when time is in year)

Program

#include<stdio.h>

#include<conio.h>

void main()

{

   float p, t, r, si;

   // taking input of principal

   printf("\n Enter the value of principle amount:");

   scanf("%f",&p);

   // taking input of time

   printf("\n Enter Time (In year):");

   scanf("%f", &t);

   // taking input of rate

   printf("\n Enter rate percent:");

   scanf("%f",&r);

   // Using formula of simple interest

   si = (p*t*r)/100;

   // printing simple interest

   printf("\n Simple interest = %f", si);

   getch();

}

 Output

Simple interest in C time in year


C program to calculate simple interest (when time is in a month)


In simple interest when time is in months, it needs to convert months into years

How to convert month into the year 
  
12 month = 1 year
1 month = (1/12) year

For example 
 5 months = (5/12) year

so, the formula of calculating simple interest (if time is in months ) is
SI = (P*T*R)/(12*100)
    = (P*T*R)/1200
                
Where SI = simple interest
            P = Principal amount
            T = Time (in month)

Program 

#include<stdio.h>

#include<conio.h>

void main()

{

   float p, t, r, si;

   // taking input of principal

   printf("\n Enter the value of principle amount:");

   scanf("%f",&p);

   // taking input of time

   printf("\n Enter Time (In month):");

   scanf("%f", &t);

   // taking input of rate

   printf("\n Enter rate percent:");

   scanf("%f",&r);

   // converting time month into year and using simple interest formula

   si = (p*t*r)/1200;

   // printing simple interest

   printf("\n Simple interest = %f", si);

   getch();

   }

 Output


Simple interest in C time in month


In some cases, we have to write a C program to calculate simple interest when time is given in days. In time, the time must be converted from days to years.

How to convert time days to years
365 days = 1 years
1 days = (1/365)year
for example
200 days  = (200/365) year
 
So, formula to calculate simple interest (if time is in days) is 
SI = (P*T*R)/(100*365)
    =(P*T*R)/36500
 
Program                       

#include<stdio.h>

#include<conio.h>

void main()

{

   float p, t, r, si;

   // taking input of principal

   printf("\n Enter the value of principle amount:");

   scanf("%f",&p);

   // taking input of time

   printf("\n Enter Time (In days):");

   scanf("%f", &t);

   // taking input of rate

   printf("\n Enter rate percent:");

   scanf("%f",&r);

   // converting time days into year and using simple interest formula

   si = (p*t*r)/36500;

   // printing simple interest

   printf("\n Simple interest = %f", si);

   getch();

 }

                
Output
Simple interest in C time in days


Post a Comment

0 Comments