TCS MockVita Solution : Problem B

Problem : The power of compounding

Manish has realized the power of compounding. Since the days he started earning, he has diligently set aside a small corpus which he saves from his monthly salary and deposits in his bank account. Bank pays him interest every month.

Manish is also a determined investor and refrains from withdrawing anything from this account because he now believes in power of compounding. Given investment corpus, fixed annual rate of interest and maturity period calculate the amount the Manish will end up saving at the end of his tenure.


Input Format:

First line contains investment corpus P
Second line contains rate of interest per annum R
Third line contains tenure T (in months)

Output Format:

Print the maturity amount after specified tenure in the format "Final_Amount <Value>"

Constraints:

P > 0 ; it can be float value
R >=0 ; it can be float value
T >0 ; it can be integer only
Calculation should be done upto 11digit precision
Maturity amount should be printed, rounded off to its nearest integer value

Sample Input 1

25
4
6

Sample Output 1

Final_Amount 152

Sample Input 2

52.50
3.6
5

Sample Output 2

Final_Amount 265

Sample Input 3

500
3.6
MARCH

Sample Output 3

Invalid Input

C Implementation:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int check(char *s)
{
 for(int i=0;s[i];i++)
 {
  if(!isdigit(s[i]))
   return 0;
 }
 return 1;
}

int main(void) {
 double p,r;
 double interest;
 int amount;
 char t[100];
 double ta;
 char *ptr;
 scanf("%lf %lf",&p,&r);
 scanf("%s",t);
 if(!check(t))
 {
  printf("Invalid Input");
 }
 else
 {
  ta = strtod(t,&ptr);
  p = p * ta;
  r = (r/12) * ta;
  ta = ta/12;
  interest = p * pow((1+(r/100)),ta);
  amount = ceil(interest);
  printf("Final_Amount %d",amount);
 }

 return 0;
}

Note: Some of the test cases are failing. You can contribute your own solution or can give suggestions here to help other aspirants. All you need to do is, Just paste your code down in comments or send an email to sathish@coderegister.co.in. Your code will appear in few minutes.

Other Problems from TCS Mockvita - 1 and Mockvita - 2:

Solution : MockVita-I Problem D

Solution : MockVita-II Problem C

Solution : MockVita-II Problem B

Solution : MockVita-II Problem D

Solution : MockVita-II Problem A

Solution : MockVita-I Problem B

Solution : MockVita-I Problem C

Solution : MockVita-I Problem F

Solution : MockVita-I Problem A