Saturday 5 September 2015

Question 2

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 integerConstraints: 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


here is my code freinds  (this problem gave me some trouble)

by looking at the code you may think this was easy but frankly this took the most amount of my time to get it right(because of  a small trick)

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float m,p,r;
double x,b;
int c;
scanf("%f%f%f",&p,&m,&r);
b=1200+r*(m-1);
x=p*m*1200/b;
c=(int)x;
printf("the amount to be deposited is :%d\n",c);
getch();
}

6 comments:

  1. can you explain which trick you used here

    ReplyDelete
    Replies
    1. i just analyzed the problem considered all the variables that influenced the result.(trick is for 1 month you will not have the interest after depositing the money).so total intrest minus one month interest thats it

      Delete
  2. can you explain the problem please

    ReplyDelete
  3. please explain the question and tell me why you have taken 1200 in the code.

    ReplyDelete
    Replies
    1. This was 5 years ago and its not worth my time to explain it. But the 1200 in the code probably represents time (look for simple interest formulas)

      Delete
  4. Nehayti wrong code hai. LOL

    ReplyDelete