C Tutorial

# C program to compute PMT (periodic payment) for a loan

## C program to compute PMT for a loan

This program is used to compute periodic payment (partial pay off + constant interest) and also called EMI calculator.

EMI is equated monthly installment (partial pay off + interest).

In this program, written PMT function is a financial function that returns the periodic payment for a loan.

PMT function is one of the financial functions to calculate the payment for a loan based on constant payments and a constant interest rate.

In this program, interest rate, loan amount, number of years for loan and number of EMI's per year are the inputs and computes periodic payment for a loan.

here we have not rounded up the decimal values, let us see how to round up decimal values in another section.

PeriodicPayment function has the core logic to compute the PMT.

```#include<stdio.h>
#include<math.h>

float PMT (int interest, int loan_amount, int total_months, int num_of_emi_per_year) {
float rate, denominator;
rate = (float) interest/(100*num_of_emi_per_year);
denominator = pow((1+rate), total_months)-1;
return (rate+(rate/denominator))*loan_amount;
}
void main()
{
int loan_amount, loan_term_years, num_of_emi_per_year,total_months;
float rate_of_interest, pmt_value;

printf("\nEnter loan amount: ");
scanf("%d", &loan_amount);

printf("\nEnter loan tearm in years: ");
scanf("%d", &loan_term_years);

printf("\nEnter number of EMI per year: ");
scanf("%d", &num_of_emi_per_year);

printf("\nEnter rate of interest: ");
scanf("%f", &rate_of_interest);
total_months = loan_term_years*num_of_emi_per_year;
pmt_value= PeriodicPayment(rate_of_interest, loan_amount, total_months, num_of_emi_per_year);
printf("\nEMI: %f", pmt_value);
}
```

Output:

```\$ cc emi_calculator.c -lm
\$ ./a.out

Enter loan amount: 396000

Enter loan tearm in years: 4

Enter number of EMI per year: 12

Enter rate of interest: 15

EMI: 11020.946289
```

C Tutorial