C Tutorial
This c program is used to compute the EMI (equated monthly installment) and convert to smallest integer value which is greater than or equal to the EMI decimal value.
C predefined function returns the smallest integer value greater than or equal to parameter value.
double ceil(double)
if we are invoking ceil function for parameter 17.8 like ceil(17.8) then returns 18.00000.
for ceil(17.2) also returns 18.00000 and it's not actual round up value.
Let's see how we can round up the emi decimal value using ceil function in below program,
#include<stdio.h> #include<math.h> float EMI (int interest, int loan_amount, int total_months) { float rate, denominator; rate = (float) interest/(100*12); 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; float rate_of_interest, pmt_value, pmt_ceil_val; 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= EMI(rate_of_interest, loan_amount, loan_term_years*num_of_emi_per_year); pmt_ceil_val = ceil(pmt_value); printf("\nEMI: %f", pmt_ceil_val); }
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: 11021.00000
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page