Join Regular Classroom : Visit ClassroomTech

Mathematical Computation Problem | Saving Money | Codewindow.in

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

Example
Input:
500
3
12

Output:
1470

Solution: In C

#include<stdio.h>
int main() {
    int t,x,i;
    float temp, r,m;
    scanf("%f%d%f",&m,&t,&r);
    temp=m;
    while(t--) { 
        temp=(temp*1200)/(1200+r);
        temp+=m;
    }
    x=(int)temp;
    printf("%d",x-(int)m);
    return 0;
}

Solution: In Java

import java.util.Scanner;
class Deposit{
    public static void main(String args[]){
        int t,x,i;
        float temp,r,m;
        Scanner sc = new Scanner(System.in);
        m = sc.nextInt();
        t = sc.nextInt();
        r = sc.nextInt();
        temp=m;
        while(t-->0) {
            temp=(temp*1200)/(1200+r);
            temp+=m;
        }
        x=(int)temp;
        System.out.printf("%d",x-(int)m);
    }
}

Solution: In Python 3

m= int(input())
T= int(input())
r= int(input())
Temp = m
while T>0:
    Temp=(Temp*1200)/(1200+r)
    Temp = Temp + m
    T = T-1
print(int(Temp)-int(m))

Also Checkout

Recent Posts
Categories
Pages