Saturday, July 14, 2018

TCS CodeVita Problem : The power of compounding C-language Program

Problem : The power of compounding - Nareddula Rajeev Reddy (NRR)

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>"


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



Sample Output 1

Final_Amount 152

Sample Input 2



Sample Output 2

Final_Amount 265

Sample Input 3



Sample Output 3

Invalid Input

TCS CodeVita 2018 Round1 Question: The power of compounding
C-Language Program (MockVita1/Problem B)

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

int check(char *s)
 for(int i=0;s[i];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);
  printf("Invalid Input");
  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;


* Ask us, what you want?