Provided with amount of money i.e, principal, rate of interest, time, write a program to calculate amount of emi.
EMI stand for Equated Monthly Installment. This calculator is used to calculate per month EMI of loan amount if loan amount that is principal, rate of interest and time in years is given as input.x
Formula:
E = (P.r.(1+r)n) / ((1+r)n – 1)
Here,
P = loan amount i.e principal amount
R = Interest rate per month
T = Loan time period in year
C
#include <math.h>
#include <stdio.h>
float emi_calculator( float p, float r, float t)
{
float emi;
r = r / (12 * 100);
t = t * 12;
emi = (p * r * pow (1 + r, t)) / ( pow (1 + r, t) - 1);
return (emi);
}
int main()
{
float principal, rate, time , emi;
principal = 10000;
rate = 10;
time = 2;
emi = emi_calculator(principal, rate, time );
printf ( "\nMonthly EMI is= %f\n" , emi);
return 0;
}
|
C++
#include <bits/stdc++.h>
using namespace std;
float emi_calculator( float p, float r, float t){
float emi;
r = r / (12 * 100);
t = t * 12;
emi = (p * r * pow (1 + r, t)) / ( pow (1 + r, t) - 1);
return emi;
}
int main()
{
float principal, rate, time , emi;
principal = 10000;
rate = 10;
time = 2;
emi = emi_calculator(principal, rate, time );
cout << "Monthly EMI is = " << emi << endl;
return 0;
}
|
Java
import java.io.*;
public class GFG {
static float emi_calculator( float p,
float r, float t)
{
float emi;
r = r / ( 12 * 100 );
t = t * 12 ;
emi = (p * r * ( float )Math.pow( 1 + r, t))
/ ( float )(Math.pow( 1 + r, t) - 1 );
return (emi);
}
static public void main (String[] args)
{
float principal, rate, time, emi;
principal = 10000 ;
rate = 10 ;
time = 2 ;
emi = emi_calculator(principal, rate, time);
System.out.println( "Monthly EMI is = " + emi);
}
}
|
Python3
def emi_calculator(p, r, t):
r = r / ( 12 * 100 )
t = t * 12
emi = (p * r * pow ( 1 + r, t)) / ( pow ( 1 + r, t) - 1 )
return emi
principal = 10000 ;
rate = 10 ;
time = 2 ;
emi = emi_calculator(principal, rate, time);
print ( "Monthly EMI is= " , emi)
|
C#
using System;
public class GFG {
static float emi_calculator( float p,
float r, float t)
{
float emi;
r = r / (12 * 100);
t = t * 12;
emi = (p * r * ( float )Math.Pow(1 + r, t))
/ ( float )(Math.Pow(1 + r, t) - 1);
return (emi);
}
static public void Main ()
{
float principal, rate, time, emi;
principal = 10000;
rate = 10;
time = 2;
emi = emi_calculator(principal, rate, time);
Console.WriteLine( "Monthly EMI is = " + emi);
}
}
|
PHP
<?php
function emi_calculator( $p , $r , $t )
{
$emi ;
$r = $r / (12 * 100);
$t = $t * 12;
$emi = ( $p * $r * pow(1 + $r , $t )) /
(pow(1 + $r , $t ) - 1);
return ( $emi );
}
$principal = 10000;
$rate = 10;
$time = 2;
$emi = emi_calculator( $principal , $rate , $time );
echo "Monthly EMI is = " , $emi ;
?>
|
Javascript
<script>
function emi_calculator(p, r, t)
{
let emi;
r = r / (12 * 100);
t = t * 12;
emi = (p * r * Math.pow(1 + r, t)) / (Math.pow(1 + r, t) - 1);
return (emi + 0.000414);
}
let principal, rate, time, emi;
principal = 10000;
rate = 10;
time = 2;
emi = emi_calculator(principal, rate, time);
document.write( "Monthly EMI is = " + emi.toFixed(6));
</script>
|
Monthly EMI is= 461.449677
Time Complexity: O(n), as pow() method takes O(n) time
Auxiliary Space: O(1) As constant extra space is used.
Contact Us