_ap_ufes{"success":true,"siteUrl":"techblix.com","urls":{"Home":"http://techblix.com","Category":"http://techblix.com/category/3g-4g-plans/","Archive":"http://techblix.com/2017/02/","Post":"http://techblix.com/use-reliance-jio-4g-sim-3g-devices-tricks-proven-work-jio-4g-sim/","Page":"http://techblix.com/guestsponsored-posts/","Attachment":"http://techblix.com/use-reliance-jio-4g-sim-3g-devices-tricks-proven-work-jio-4g-sim/j43g-10/","Nav_menu_item":"http://techblix.com/indianist-2/","Custom_css":"http://techblix.com/sahifa/","Wpcf7_contact_form":"http://techblix.com/?post_type=wpcf7_contact_form&p=5633","Wysijap":"http://techblix.com/?wysijap=subscriptions","Feedback":"http://techblix.com/?post_type=feedback&p=7719"}}_ap_ufee
Breaking News

Important TCS CodeVita Questions Solved – Saving for a rainy day

Important  TCS CodeVita Questions Solved – 2015

 

important tcs codevita questions solved

 

Problem : Saving for a rainy day

By nature, an average Indian believes in saving money. Some reports suggest that an average Indian manages to save approximately 30+% of his salary. Dhaniram is one such hard working fellow. With a view of future expenses, Dhaniram resolves to save a certain amount in order to meet his cash flow demands in the future.

Consider the following example.

Dhaniram wants to buy a TV. He needs to pay Rs 2000/- per month for 12 installments to own the TV. If let’s say he gets 4% interest per annum on his savings bank account, then Dhaniram will need to deposit a certain amount in the bank today, such that he is able to withdraw Rs 2000/- per month for the next 12 months without requiring any additional deposits throughout.

Your task is to find out how much Dhaniram should deposit today so that he gets assured cash flows for a fixed period in the future, given the rate of interest at which his money will grow during this period.

Input Format:

First line contains desired cash flow M
Second line contains period in months denoted by T
Third line contains rate per annum R expressed in percentage at which deposited amount will grow

Output Format:

Print total amount of money to be deposited now rounded off to the nearest integer

Constraints:

M > 0

T > 0

R >= 0

Calculation should be done upto 11-digit precision

 

Sample Input and Output

SNo.
Input
Output
1
500
3
12
1470
2
6000
3
5.9
17824
3
500
2
0
1000

Important TCS CodeVita Questions Solved – Saving for a rainy day

Sample Solution C Program:

#include<stdio.h>
#include<math.h>
int main()
{
int M,T;
float R,A,I,RM;
scanf(“%d”,&M);
scanf(“%d”,&T);
scanf(“%f”,&R);
RM=M;
T–;
while(T>0)
{
A=RM/(1+R/(float)1200);
I=RM-A;
RM+=M-I;
T–;
}
A=RM/(1+R/(float)1200);
I=RM-A;
RM-=I;
double r=ceil(RM-0.5);
if(r>RM)
r=ceil(RM);
else
r=floor(RM);
printf(“%.lf”,r);
return 0;
}

 

Program logic:

here, a while loop is used to calculate present amount of every month for withdrawing the given amount

required amount= present amount+ present amount * interset% / deposit period

deposit period=1/12

interest%=interest rate/100

=> present amount=required amount/(1+interest rate/1200)

since we know last required amount we only need to iterate the loop T-1 times and later subtract last interest from the required amount.

** using your own logic is better. Program seems easy but your logical approach matters. Also suggest your solution to this problem by commenting.

 

** check other solved codevita questions

Check Also

reliance jio logo

How to use Reliance Jio 4G SIM on 3G devices – Tricks Proved to Work

Use Jio 4G SIM on 3G devices – 100% tested The main issue with Reliance Jio …

10 comments

  1. WHY THE HELL DOES THIS CODE NOT WORK..?

    #include
    #include
    int main()
    {
    double fac=0.11f,m=0.11f,r=0.11f,ans=0.11f;
    int t;
    scanf(“%lf %d %lf”,&m,&t,&r);fac=1-(r/1200.11f);
    printf(“–%lf–“,fac);
    ans=(ans+t*m)*pow(fac,t-1);
    int x=(int)(round(ans));
    printf(“%d”,x);
    return 0;
    }

  2. this doesnt solve allt the test cases

  3. Incorrect Answer

    • friend, codevita contest is meant to test your programming skills and not your copy pasting skills. try to use your logic by refering my code, the code is now updated

Leave a Reply

error: Right Click is Disabled !!