C++ Program for Bank Compare Problem (TCS Codevita) | PrepInsta

Python program for Bank Compare

Bank Compare Problem

Bank Compare Problem is one of the sample problems of TCS CodeVita Season 9 2020 competition, it is an easy problem if compared to the standards of TCS CodeVita. In this problem the programmer has to compare two banks who are providing different rate of interests annually on a certain principal, and find out that which bank will be more beneficial for the user

Problem Description

Question – : 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))

 

Constraints:

  • 1 <= P <= 1000000
  • 1 <=T <= 50
  • 1<= N1 <= 30
  • 1<= N2 <= 30

 

Input Format:

  • First line: P principal (Loan Amount)
  • Second line: T Total Tenure (in years).
  • Third Line: N1 is the number of slabs of interest rates for a given period by Bank A. First slab starts from the first year and the second slab starts from the end of the first slab and so on.
  • Next N1 line will contain the interest rate and their period.
  • After N1 lines we will receive N2 viz. the number of slabs offered by the second bank.
  • Next N2 lines are the number of slabs of interest rates for a given period by Bank B. The first slab starts from the first year and the second slab starts from the end of the first slab and so on.
  • The period and rate will be delimited by single white space.

 

Output Format: Your decision either Bank A or Bank B.

 

Explanation:

  • Example 1
    • Input
    • 10000
    • 20
    • 3
    • 5 9.5
    • 10 9.6
    • 5 8.5
    • 3
    • 10 6.9
    • 5 8.5
    • 5 7.9
  • Output: Bank B

 

  • Example 2
    • Input
    • 500000
    • 26
    • 3
    • 13  9.5
    • 3  6.9
    • 10  5.6
    • 3
    • 14  8.5
    • 6  7.4
    • 6  9.6
  • Output: Bank A

 

C++ Code

#include  <iostream> 
#include  <math.h> 
using namespace std;
int main() 
{
double p,s,mi,sum,emi,bank[5],sq;
int y,n,k,i,yrs,l=0;

cin>>p;
cin>>y;
for(k=0;k<2;k++) { cin>>n;
sum=0;
for(i=0;i<n;i++) { cin>>yrs;
  cin>>s;
  mi=0;
  sq=pow((1+s),yrs*12);
  emi= (p*(s))/(1-1/sq);
  sum= sum + emi;
}
bank[l++]=sum;

}

if(bank[0]<bank[1])

cout<<("Bank A");

else

cout<<("Bank B");

return 0;

}
Output
10000
20
3
5 9.5
10 9.6
5 8.5
3
10 6.9
5 8.5
5 7.9
Bank B

Bank Compare Problem in Other Coding Languages

C

To find the solution of Bank Compare problem in C Programming language click on the button below:

C

Python

To find the solution of Bank Compare problem in Python Programming language click on the button below:

Python

Java

To find the solution of Bank Compare problem in Java Programming language click on the button below:

Java

5 comments on “C++ Program for Bank Compare Problem (TCS Codevita) | PrepInsta”


  • Ebad

    #include
    #include
    using namespace std;

    int main(int argc, char *argv[])
    {
    long P, T;
    int n;
    double temp1, temp2;

    long double N1 = 0;
    long double N2 = 0;
    cin >> P >> T;

    P /= 100;

    cin >> n;
    for (int i = 0; i > temp1 >> temp2;
    N1 += P * temp1 * temp2;
    }

    cin >> n;
    for (int i = 0; i > temp1 >> temp2;
    N2 += P * temp1 * temp2;
    }

    if (N1 < N2)
    cout << "Bank A";
    else
    cout << "Bank B";

    return 0;
    }


  • Shashank

    #include
    #include
    using namespace std;
    int main()
    {
    int p,t,n1,n2;
    float tenureA,rateA,tenureB,rateB,sum=0,interest1,interest2;
    cin>>p>>t>>n1;
    for(int i=0;i>tenureA>>rateA;
    float emi= p*rateA/(1-1/pow((1+rateA),(tenureA*12)));
    sum=sum+(emi);
    }
    interest1=sum-p;
    sum=0;
    cin>>n2;
    for(int i=0;i>tenureB>>rateB;
    float emi= p*rateB/(1-1/pow((1+rateB),(tenureB*12)));
    sum=sum+(emi);
    }
    interest2=sum-p;

    if(interest1>interest2)
    {

    cout<<"Bank B";
    }
    else{
    cout<<"Bank A";
    }
    }
    code is giving the right answer….but
    How can I optimize this code further….??


    • HelpPrepInsta

      Its simple Shubham, we are just comparing the returns of two banks on the same prinicipal amount, and then we are choosing the bank which has the higher returns