Program for EMI Calculator in C program

CServer Side ProgrammingProgramming

Given with certain values the program will develop an EMI calculator to generate the needed output. EMI stands for Equated Monthly Installment. So this calculator will generate monthly EMI amount for the user.

Example

Input-: principal = 2000
   rate = 5
   time = 4
Output-: Monthly EMI is= 46.058037

The formula used in the below program is −

EMI : (P*R*(1+R)T)/(((1+R)T)-1)

where,

P indicates loan amount or the Principal amount.

R indicates interest rate per month

T indicates loan time period in year

Approach used below is as follows

  • Input principal, rate of interest and time in float variable
  • Apply the formula to calculate the EMI amount
  • Print the EMI amount

Algorithm

Start
Step 1 -> Declare function to calculate EMI
   float calculate_EMI(float p, float r, float t)
      float emi
      set r = r / (12 * 100)
      Set t = t * 12
      Set emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1)
      Return emi
Step 2 -> In main()
   Declare variable as float principal, rate, time, emi
   Set principal = 2000, rate = 5, time = 4
   Set emi = calculate_EMI(principal, rate, time)
   Print emi
Stop

Example

#include <math.h>
#include <stdio.h>
// Function to calculate EMI
float calculate_EMI(float p, float r, float t){
   float emi;
   r = r / (12 * 100); // one month interest
   t = t * 12; // one month period
   emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1);
   return (emi);
}
int main(){
   float principal, rate, time, emi;
   principal = 2000;
   rate = 5;
   time = 4;
   emi = calculate_EMI(principal, rate, time);
   printf("\nMonthly EMI is= %f\n", emi);
   return 0;
}

Output

Monthly EMI is= 46.058037
raja
Published on 20-Sep-2019 11:44:49
Advertisements