HackerRank C- Bank Compare



There are two banks; Bank A and Bank B. Their interest rates vary. You have received offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of interest over the entire tenure.

You have to choose the offer which costs you least interest and reject the other. Do the computation and make a wise choice.

The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :

EMI = loanAmount * monthlyInterestRate / ( 1 – 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))



  1. #include <stdio.h>
  2. #include<math.h>
  3. int main() {
  4. double p,s,mi,sum,emi,bank[5],sq;
  5. int y,n,k,i,yrs,l=0;
  6. scanf("%lf",&p);
  7. scanf("%d",&y);
  8. for(k=0;k<2;k++)
  9. {
  10. scanf("%d",&n);
  11. sum=0;
  12. for(i=0;i<n;i++)
  13. {
  14. scanf("%d",&yrs);
  15. scanf("%lf",&s);
  16. mi=0;
  17. sq=pow((1+s),yrs*12);
  18. emi= (p*(s))/(1-1/sq);
  19. sum= sum + emi;
  20. }
  21. bank[l++]=sum;
  22. }
  23. if(bank[0]<bank[1])
  24. printf("Bank A");
  25. else
  26. printf("Bank B");
  27. return 0;
  28. }

download android app