C Tutorial
This c program is used to compute the list of EMI's for a loan with corresponding interest, principal and balance for every months.
perioric_payment function is used to compute the EMI for every month.
round_up function is used to round up the decimal values to integer value near by using floor function.
Using while loop to compute the interest, principal and balance for every months.
floor function is used to round up the nearest integer value from decimal values for interest, principal, balance etc..
floating values are formated in EMI tables.
#include<stdio.h> #include<math.h> float perioric_payment (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; } float round_up(float val) { int floor_val, round_val; floor_val = floor(val); if(val >= (floor_val+0.5)) { round_val = floor_val +1; } else { round_val = floor_val; } return round_val; } void main() { int loan_amount, loan_term_years, num_of_emi_per_year, i; float rate_of_interest, pmt_value, pmt_floor_val, emi_interest, emi_principal, balance; 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); pmt_value= PMT(rate_of_interest, loan_amount, (loan_term_years*num_of_emi_per_year), num_of_emi_per_year); pmt_value = round_up(pmt_value); printf("\n---------------------------------------------------------------------------------------------------"); printf("\nEMI\t\tInterest\t\tPrincipal\t\tBalance"); printf("\n---------------------------------------------------------------------------------------------------"); balance = loan_amount; while(balance>0) { emi_interest = round_up((balance*rate_of_interest)/(num_of_emi_per_year*100)); emi_principal =round_up( pmt_value - emi_interest); balance = round_up(balance - emi_principal); printf("\n%10.2f\t\t%10.2f\t\t%10.2f\t\t%10.2f", pmt_value, emi_interest, emi_principal, balance); } printf("\n---------------------------------------------------------------------------------------------------"); }
Output:
$ cc emi_table.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 Interest Principal Balance --------------------------------------------------------------------------------------------------- 11021.00 4950.00 6071.00 389929.00 11021.00 4874.00 6147.00 383782.00 11021.00 4797.00 6224.00 377558.00 11021.00 4719.00 6302.00 371256.00 11021.00 4641.00 6380.00 364876.00 11021.00 4561.00 6460.00 358416.00 11021.00 4480.00 6541.00 351875.00 11021.00 4398.00 6623.00 345252.00 11021.00 4316.00 6705.00 338547.00 11021.00 4232.00 6789.00 331758.00 11021.00 4147.00 6874.00 324884.00 11021.00 4061.00 6960.00 317924.00 11021.00 3974.00 7047.00 310877.00 11021.00 3886.00 7135.00 303742.00 11021.00 3797.00 7224.00 296518.00 11021.00 3706.00 7315.00 289203.00 11021.00 3615.00 7406.00 281797.00 11021.00 3522.00 7499.00 274298.00 11021.00 3429.00 7592.00 266706.00 11021.00 3334.00 7687.00 259019.00 11021.00 3238.00 7783.00 251236.00 11021.00 3140.00 7881.00 243355.00 11021.00 3042.00 7979.00 235376.00 11021.00 2942.00 8079.00 227297.00 11021.00 2841.00 8180.00 219117.00 11021.00 2739.00 8282.00 210835.00 11021.00 2635.00 8386.00 202449.00 11021.00 2531.00 8490.00 193959.00 11021.00 2424.00 8597.00 185362.00 11021.00 2317.00 8704.00 176658.00 11021.00 2208.00 8813.00 167845.00 11021.00 2098.00 8923.00 158922.00 11021.00 1987.00 9034.00 149888.00 11021.00 1874.00 9147.00 140741.00 11021.00 1759.00 9262.00 131479.00 11021.00 1643.00 9378.00 122101.00 11021.00 1526.00 9495.00 112606.00 11021.00 1408.00 9613.00 102993.00 11021.00 1287.00 9734.00 93259.00 11021.00 1166.00 9855.00 83404.00 11021.00 1043.00 9978.00 73426.00 11021.00 918.00 10103.00 63323.00 11021.00 792.00 10229.00 53094.00 11021.00 664.00 10357.00 42737.00 11021.00 534.00 10487.00 32250.00 11021.00 403.00 10618.00 21632.00 11021.00 270.00 10751.00 10881.00 11021.00 136.00 10885.00 -4.00 ---------------------------------------------------------------------------------------------------
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page