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
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
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++)
{
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;
}
Source:
https://www.google.in/