Vous êtes sur la page 1sur 31

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

Sample Input and Output


SNo.

Input

Output

500
1

1470

12
6000
2

17824

5.9
3

500

1000

2
0
Important TCS CodeVita Questions Solved Saving for a rainy day
Sample Solution C Program:
#include<stdio.h>
#include<math.h>
int main()
{
int M,T;
float R,A,I,RM;
scanf(%d,&M);
scanf(%d,&T);
scanf(%f,&R);
RM=M;
T;
while(T>0)
{
A=RM/(1+R/(float)1200);
I=RM-A;
RM+=M-I;
T;
}
A=RM/(1+R/(float)1200);
I=RM-A;
RM-=I;
double r=ceil(RM-0.5);
if(r>RM)
r=ceil(RM);
else
r=floor(RM);
printf(%.lf,r);
return 0;
}

Program logic:
here, a while loop is used to calculate present amount of every month for withdrawing the given
amount
required amount= present amount+ present amount * interset% / deposit period

deposit period=1/12
interest%=interest rate/100
=> present amount=required amount/(1+interest rate/1200)
since we know last required amount we only need to iterate the loop T-1 times and later subtract last
interest from the required amount.
** using your own logic is better. Program seems easy but your logical approach matters. Also
suggest your solution to this problem by commenting.

Problem : Catch-22
A robot is programmed to move forward F meters and backwards again, say B meters, in a straight
line. The Robot covers 1 meter in T units of time. On Robots path there is a ditch at a distance FD
from initial position in forward direction as well as a ditch at a distance BD from initial position in
backward direction. This forward and backward movement is performed repeatedly by the Robot.
Your task is to calculate amount of time taken, before the Robot falls in either ditch, if at all it falls in a
ditch.
Input Format:
First line contains total number of test cases, denoted by N
Next N lines, contain a tuple containing 5 values delimited by space
F B T FD BD, where
1.

F denotes forward displacement in meters

2.

B denotes backward displacement in meters

3.

T denotes time taken to cover 1 meter

4.

FD denotes distance from Robots starting position and the ditch in forward direction

5.

BD denotes distance from Robots starting position and the ditch in backward direction

Output Format:
For each test case print time taken by the Robot to fall in the ditch and also state which ditch he falls
into. Print F for forward and B for backward. Both the outputs must be delimited by whitespace
OR
Print No Ditch if the Robot does not fall in either ditch

Constraints:
First move will always be in forward direction
1 <= N <= 100
forward displacement > 0
backward displacement > 0
time > 0
distance of ditch in forward direction (FD) > 0
distance of ditch in backward direction (BD) > 0
All input values must be positive integers only

Sample Input and Output


SNo.

Input
3

9 4 3 13 10
9 7 1 11 13
4 4 3 8 12
5
8 4 7 11 22

4 5 4 25 6
4 9 3 6 29
7 10 6 24 12
10 10 1 9 7

Output
63 F
25 F
No Ditch

133 F
216 B
231 B
408 B
9F

Important TCS CodeVita Questions Solved catch22 Problem


Sample Solution in C :
#include<stdio.h>
int main()
{
int N,F,B,T,FD,BD,d;
scanf("%d",&N);
while(N>0)
{
scanf("%d %d %d %d %d",&F,&B,&T,&FD,&BD);

if(F==B && F<FD && B<BD)


printf("NO Ditch\n");
else
{
d=0;
while(FD>0 && BD>0)
{
d+=F;
FD-=F;
BD+=F;
if(FD>0)
{
d+=B;
FD+=B;
BD-=B;
}
}
if(FD<=0)
{
d+=FD;
printf("%d F\n",d*T);
}
else if(BD<=0)
{

d+=BD;
printf("%d B\n",d*T);
}
}
N--;
}
return 0;
}

Problem : Milk Man and His Bottles


A Milkman serves milk in packaged bottles of varied sizes. The possible size of the bottles are {1, 5, 7
and 10} litres. He wants to supply desired quantity using as less bottles as possible irrespective of the
size. Your objective is to help him find the minimum number of bottles required to supply the
given demand of milk.

Input Format:
First line contains number of test cases N
Next N lines, each contain a positive integer Li which corresponds
to the demand of milk.

Output Format:
For each input Li, print the minimum number of bottles required to
fulfill the demand

Constraints:
1<= N <= 1000
Li> 0
1<= i <= N
Sample Input and Output
SNo.

Input

Output

2
1

17

65

Explanation:
Number of test cases is 2
1.

In first test case, demand of


milk is 17 litres which can be supplied using minimum of 2 bottles as
follows
o

1 x 10 litres and

1 x 7 litres

2. In second test case, demand of


milk is 65 litres which can be supplied using minimum of 7 bottles as
follows
o

6 x 10 litres and

1 x 5 litres

Solved Previous years TCS CodeVita questions Milk Man and His Bottles
Sample Solution in C Programming:
#include<stdio.h>
int main()
{
int b,n,l;
scanf("%d",&n);
while(n>0)
{
scanf("%d",&l);
b=0;
while(l>0)

{
b++;
if(l>=10)
l=l-10;
else if(l>=7)
l=l-7;
else if(l>=5)
l=l-5;
else
l=l-1;
}
printf("%d\n",b);
n--;
}
return 0;
}

Problem : Matrix Rotations


You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in
clockwise direction byS degrees, where S is angle of rotation. On the matrix, there will be 3 types of
operations viz.
1.

Rotation
Rotate the matrix A by angle S, presented as input in form of A S

2.

Querying
Query the element at row K and column L, presented as input in form of Q K L

3.

Updation
Update the element at row X and column Y with value Z, presented as input in form of U X Y Z

Print the output of individual operations as depicted in Output Specification

Input Format:
Input will consist of three parts, viz.
1. Size of the matrix (N)
2. The matrix itself (A = N * N)
3. Various operations on the matrix, one operation on each line. (Beginning either with A, Q or U)
-1 will represent end of input.
Note:

Angle of rotation will always be multiples of 90 degrees only.

All Update operations happen only on the initial matrix. After update all the previous rotations
have to be applied on the updated matrix

Output Format:
For each Query operation print the element present at K-L location of the matrix in its current state.

Constraints:
1<=N<=1000
1<=Aij<=1000
0<=S<=160000
1<=K, L<=N
1<=Q<=100000
Sample Input and Output
SNo.

Input

Output

2
12
34
A 90
Q11
1

Q12
A 90
Q11
U116
Q22
-1

Explanation:

3
1
4
6

Initial Matrix
12
34
After 90 degree rotation, the matrix will become
31
42
Now the element at A11 is 3 and A12 is 1.
Again the angle of rotation is 90 degree, now after the rotation the matrix will become
43
21
Now the element at A11 is 4.
As the next operation is Update, update initial matrix i.e.
62
34
After updating, apply all the previous rotations (i.e. 180 = two 90 degree rotations).
The matrix will now become
43
26
Now A22 is 6.

TCS CodeVita previous years questions Matrix Rotation solution


Sample Solution C proram code :
#include<stdio.h>
int i,j,n,arr1[1000][1000],arr2[1000][1000];
void swaparray()
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr1[i][j]=arr2[i][j];
}

int main()
{
char opt[4];
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&arr1[i][j]);
scanf("%s",opt);
while(strcmp(opt,"-1"))
{
if(opt[0]=='A')
{
if(!strcmp(opt,"A90"))
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr2[j][n-i-1]=arr1[i][j];
swaparray();
}
else if(!strcmp(opt,"A180"))
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr2[n-i-1][n-j-1]=arr1[i][j];

swaparray();
}
else if(!strcmp(opt,"A270"))
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr2[n-j-1][i]=arr1[i][j];
swaparray();
}
else if(!strcmp(opt,"A0") || !strcmp(opt,"A360")); //not required
}
else if(opt[0]=='Q')
{
if(opt[1]-48<n && opt[2]-48<n)
printf("%d\n",arr1[opt[1]-48][opt[2]-48]);
}
else if(opt[0]='U')
{
if(opt[1]-48<n && opt[2]-48<n)
arr1[opt[1]-48][opt[2]-48]=opt[3]-48;
}
scanf("%s",opt);
}
return 0;

Problem: A futuristic company is building an autonomous car. The scientists at the company are
training the car to perform Reverse parking. To park, the car needs to be able to move in backward as
well as forward direction. The car is programmed to move backwards B meters and forwards again,
say F meters, in a straight line. The car does this repeatedly until it is able to park or collides with
other objects. The car covers 1 meter in T units of time. There is a wall after distance D from cars
initial position in the backward direction.
The car is currently not without defects and hence often hits the wall. The scientists are devising a
strategy to prevent this from happening. Your task is to help the scientists by providing them with
exact information on amount of time available before the car hits the wall.

Tcs CodeVita Sample Question Solved


Sample Solution in C Programming:
#include<stdio.h>
int main()
{
int D,F,B,T,d,t;
printf("Distance of wall from car");
scanf("%d",&D);
printf("Forward Distance moved by car");
scanf("%d",&F);
printf("Backward Distance moved by car");
scanf("%d",&B);
printf("Unit of time taken to cover 1 meter");
scanf("%d",&T);
if(F>B)

printf("Car wont hit the wall");


else if(D<F)
printf("Time left is %d units",D*T);
else
{
d=D;t=0;
while(d>0)
{
d-=B;
t+=(B);
if(d>0)
{
d+=F;
t+=F;
}
}
if(d==0)
printf("Time left is %d units",t*T);
else
{
d+=B;
t-=B;
while(d!=0)
{

d--;
t++;
}
printf("Time left is %d units",t*T);
}
}
return 0;
}

Problem : Compiler Design Limit the Method Instructions


Raj is a newbie to the programming and while learning the programming language he came to know
the following rules:

Each program must start with { and end with }.

Each program must contain only one main function. Main function must start with < and end

with >.

A program may or may not contain user defined function(s). There is no limitation on the

number of user defined functions in the program. User defined function must start with ( and end with
).

Loops are allowed only inside the functions (this function can be either main function or user

defined function(s)). Every loop must start with { and end with }.

User defined function(s) are not allowed to be defined inside main function or other user

defined function(s).

Nested loops are allowed.

Instructions can be anywhere inside the program.

Number of instructions inside any user defined function must not be more than 100.

If any of the above conditions is not satisfied, then the program will generate compilation errors. Today
Raj has written a few programs, but he is not sure about the correctness of the programs. Your task is
to help him to find out whether his program will compile without any errors or not.
Input Format:
First line starts with T, number of test cases. Each test case will contain a single line L, where L is a
program written by Raj.
Output Format:
Print No Compilation Errors if there are no compilation errors, else print Compilation Errors.

Constraints:
1<=T<=100
L is a text and can be composed of any of the characters {, }, (, ), <, >and P, where P will
represents the instruction.
L, comprised of characters mentioned above should be single spaced delimited.
Number of characters in the text, |L| < = 10000
Sample Input and Output

SNo.

Input
3

{<>(P)}
{<{}>({}))
{({})}

Output

No Compilation Errors
Compilation Errors
Compilation Errors

Note:
Please do not use package and namespace in your code. For object oriented languages your code
should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files do not
exist in gcc

TCS CodeVita previous years questions Compiler Design solution


Sample Solution in C Programming:

#include<stdio.h>
int main()
{
int T;
char arr[100][10000];
scanf(%d,&T);
while(T>0)
{
int i,length,e=0,mf=0,nmf=0,uf=0,l=0;
scanf(%s,arr[T]);
length=strlen(arr[T]);
if(arr[T][0]!='{ || arr[T][length-1]!=})
e++;
for(i=1;i<length-1;i++)
{
if(arr[T][i]=='< && mf==0 && uf==0 && l==0)
{
mf++;
nmf++;
}
else if(arr[T][i]==> && mf==1 && uf==0 && l==0)
mf;
else if(arr[T][i]=='( && mf==0 && uf==0 && l==0)
uf++;
else if(arr[T][i]==) && mf==0 && uf==1 && l==0)
uf;
else if(arr[T][i]=='{ && (mf==1 || uf==1))
l++;
else if(arr[T][i]==} && l>0 && (mf==1 || uf==1))
l;
else if(arr[T][i]==P);
else
e++;
}
if(e!=0 || uf!=0 || mf!=0 || nmf=1 || l!=0)
printf(\nCompilation Error\n);
else
printf(\nNo Compilation Error\n);
T;
}
return 0;
}

Problem : Online Communities - Even


Groups
In a social network, online communities refer to the group of people with an interest towards the
same topic. People connect with each other in a social network. A connection between
Person I and Person J is represented as C I J. When two persons belonging to different
communities connect, the net effect is merger of both communities which I and J belonged to.
We are only interested in finding out the communities with the member count being an even
number. Your task is to find out those communities.
Input Format:
Input will consist of three parts, viz.

1. The total number of people on the social network (N)


2.Queries
C I J, connect I and J
Q 0 0, print the number of communities with even member-count
-1 will represent end of input.
Output Format:
For each query Q, output the number of communities with even member-count
Constraints:
1<=N<=10^6
1<=I, J<=N
Sample Input and Output

SNo
Input
.
1
5
Q00
C12
Q00
C23
Q00
C45

Output
0
1
0
1

Q00
-1

Explanation:
For first query there are no members in any of the groups hence answer is 0.
After C 1 2, there is a group (let's take it as G1) with 1 and 2 as members hence total count at this
moment is 1.
After C 2 3 total members in G1 will become {1, 2, 3} hence there are no groups with even count.
After C 4 5 there formed a new group G2 with {4, 5} as members, hence the total groups with even
count is 1.
Note:
Please do not use package and namespace in your code. For object oriented languages your code should
be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files do not
exist in gcc

Problem : Matrix Rotations


You are given a square matrix of dimension N. Let this matrix be called A. Your task is to
rotate A in clockwise direction byS degrees, where S is angle of rotation. On the matrix, there will
be 3 types of operations viz.
1.
Rotation
Rotate the matrix A by angle S, presented as input in form of A S

2.

Querying
Query the element at row K and column L, presented as input in form of Q K L

3.

Updation
Update the element at row X and column Y with value Z, presented as input in
form of U X Y Z

Print the output of individual operations as depicted in Output Specification

Input Format:
Input will consist of three parts, viz.
1. Size of the matrix (N)
2. The matrix itself (A = N * N)
3. Various operations on the matrix, one operation on each line. (Beginning either with A, Q or U)
-1 will represent end of input.
Note:

Angle of rotation will always be multiples of 90 degrees only.

All Update operations happen only on the initial matrix. After update all the previous
rotations have to be applied on the updated matrix
Output Format:
For each Query operation print the element present at K-L location of the matrix in its current
state.
Constraints:
1<=N<=1000
1<=Aij<=1000
0<=S<=160000
1<=K, L<=N
1<=Q<=100000

Sample Input and Output

SNo
Input
.

2
12
34
A 90
Q11
Q12
A 90
Q11
U116
Q22
-1

Explanation:

Output

3
1
4
6

Initial Matrix
12
34

After 90 degree rotation, the matrix will become


31
42
Now the element at A is 3 and A is 1.
11

12

Again the angle of rotation is 90 degree, now after the rotation the matrix will become
43
21
Now the element at A is 4.
11

As the next operation is Update, update initial matrix i.e.


62
34

After updating, apply all the previous rotations (i.e. 180 = two 90 degree rotations).
The matrix will now become
43
26
Now A is 6.
22

Note:
Please do not use package and namespace in your code. For object oriented languages your code should
be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files do not
exist in gcc

Longest Progressive Sequence (CodeVita round 1 question by TCS)

Views 6535

Author: Vikash_1bf2807d (Vikash Kumar Verma) View Profile | View other


solutions by this author
Question / Problem

Problem A sequence is said to be progressive if it doesnt


decrease at any point in time. For example 1 1 2 2 is a
progressive sequence but 1 2 1 is not a progressive sequence. Let
S be the sequence and be represented by L spaced integers Ki,
now your task is to find out the first longest progressive sequence
present in the given sequence (S). Input Format: First line will
contain T, the length of the sequence and next line will contain T
spaced integers Ki (where i = 0,1, ,L). Line 1 T,where T is the
length of the sequence Line 2 Ki,where Ki is integer in sequence
separated by space Constraints: 1<=T<=10^6(one million)
1<=Ki<=10^9(one billion) Output Format: Line 1 longest
progressive sequence present in the given sequence Sample Test
Case: Input: 4 1 1 2 1 Output: 112
Solution

/**
*
* @author VIK VIKASH VIKKU
* Business Logic class
*/
import java.util.ArrayList;
import java.util.Scanner;
public class LongestProgressiveSequence {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<Integer> ls = new ArrayList<Integer>();
Integer[] temp = new Integer[0];
for (int i = 0; i < t; i++) {

int num = sc.nextInt();


if (!(ls.isEmpty())) {
if (num >=ls.get(ls.size()-1 )) {
ls.add(num);
} else {
if(ls.size()>temp.length)
temp=ls.toArray(temp);
ls.clear();
ls.add(num);
}
} else {
ls.add(num);
}
}
if(ls.size()>temp.length)
{
temp=ls.toArray(temp);
ls.clear();
}
for (int i = 0; i < temp.length; i++) {
if(i<temp.length-1)
System.out.print(temp[i]+" ");
else
System.out.println(temp[i]);
}
}
}

Problem 1
Statement: Write a program to calculate the sum of n numbers and print the sum. (Sum Of
Number)
Input Format
Line 1 An integer n - the number of integers to be added.

Line 2

various integers.

Output Format
Line 1 Single integer which corresponds to sum, followed by a new line
Sample Inputs and Outputs
Sr.No Input Output
1 3, 1,2,3 6
2 3, 10,10,10 30

Problem 2
Statement: Develop a program to sort the given sequence.(Sort The Sequence)
Program should accept input sequence to be sorted via a file. The file format of the input files is
described below. Your program should parse the input file. In case of a bad input, program should
output appropriate message as mentioned in output specification below.
The program should obey the following constraints
1. The program should detect that inputs are either positive or negative numbers
2. The program should treat any alphabets or non-numeric characters as invalid inputs
3. Use double precision data types for handling valid inputs
File Format: Each element is delimited by a comma.
Input Format:
Line 1

Absolute path of the first input file

Output Format:
Line 1

For Valid inputs

Values Before the sort:


For Invalid inputs
Invalid Input
Line 2

Corresponding element of input file where elements are seperated by space

Line 3

Values after the Ascending sort:

Line 4

Sorted sequence in ascending order where elements are seperated by space

Line 5

Values after the Descending sort:

Line 6

Sorted sequence in descending order where elements are seperated by space

Sample Inputs and Outputs

Sr.N
o
1

Input
C:/sort.txt

Input In File

Output

sort.txt : 1,2,3,2,3,1,3,1,3

Values Before the sort:


123231313
Values after the Ascending
sort:
111223333
Values after the

Descending sort:
333322111
2

C:/sort.txt

sort.txt :
0,0.001,0.01,0.0001,0.0001,0.00
00001

3
4

C:/sort.txt
C:/sort.txt

sort.txt : 2,3,2,a,b,3
sort.txt : 2,3,3,?

Values Before the sort:


0 0.001 0.01 0.0001 0.0001
0.0000001
Values after the Ascending
sort:
0 0.0000001 0.0001
0.0001 0.001 0.01
Values after the
Descending sort:
0.01 0.001 0.0001 0.0001
0.0000001 0
Invalid Input
Invalid Input

Problem 3
Statement: Write a program to find Nth prime number in a given range, inclusive of the first and
the last element in that range. Program should accept input using commmand line arguments. In
case of a bad input, program should output appropriate message as mentioned in output
specification below. (Pop Out Primes)
The problem should obey following constraints :
1. Valid range for this problem statement is between 0 and 150000 (One lakh fifty thousand)
2. First element of the range should be less than the last element in the range
3. Prime number index starts from 1
Information: A prime number (or a prime) is a natural number greater than 1 that has no
positive divisors other than 1 and itself.
Input Format
Line 1
Line 2
Line 3

From Number, say N1


To Number, say N2
Nth prime number between N1 and N2 where N >=1

Output Format
Line 1 For Valid inputs
Prime Number at Nth position in a given range,
followed by a new line
For Invalid input
Invalid Input,followed by a new line
OR
No prime number is present at this index,
followed by a new line as is applicable.
Sample Inputs and Outputs

Sr.No.

Input

Output

1
15
6

13

5
1000
94

503

1
15
9

No prime number
is present at this
index

59
96
0

Invalid Input

1
a
2

Invalid Input

Problem 4
Statement: Develop a program to add two matrices. Program should accept input matrices to be
added via files. The file format of the input files is described below. Your program should parse the
input files and construct the input matrices. In case of a bad input, program should output
appropriate message as mentioned in output specification below. Once the matrices are formed,
apply appropriate logic to see if addition is possible. If addition is possible, add the input matrices
and output the result in format specified below. (Matrix Addition)
Information: Matrix addition is the operation of adding two matrices that in turn produces
resultant third matrix which is a sum of the two input matrices.
File Format
Each row is delimited by new line character
Columns within each row are space delimited
e.g. A 3x3 matrix will be represented in the file as :
123
456
789
Input Format
Line 1 Absolute path of the first input file
Line 2 Absolute path of the second input file
Output
1. Input matrices which are inserted
2. Resultant matrix or appropriate error message in format as mentioned below
Output Format

Line 1

For Valid inputs


Input Matrix 1:
For Invalid inputs
INVALID INPUT

Line 2 to Line N+1

Corresponding rows of input matrix 1

Line N+2

Input Matrix 2:

Line N+3 to Line ...

Corresponding rows of input matrix 2

Next Line

Appropriate status message


For Valid addition operation output
Valid Matrix dimensions for addition
For Invalid addition operation output
Invalid Matrix dimensions for addition

Next Line

For Valid addition operation output


Corresponding rows of resultant matrix
For Invalid addition operation output
Cannot add matrix of dimensions Rows1xColumns1
with Rows2xColumns2
where
Rows1 = rows of first input matrix
Columns1 = columns of first input matrix
Rows2= rows of second input matrix
Columns2 = columns of second input matrix

Sample Inputs and Outputs

Sr.No
1

Input
C:/matrix1.txt
C:/matrix2.txt

Input In File
matrix1.txt :
331
592
642
matrix2.txt:
211
155
389

Output
Input Matrix 1 :
331
592
642
Input Matrix 2 :
211
155
389
Valid Matrix dimensions for addition.
54 2
6 14 7
9 12 11

C:/matrix1.txt
C:/matrix2.txt

matrix1.txt :
731
725
264
matrix2.txt :
21
15
38

Input Matrix 1 :
731
725
264
Input Matrix 2 :
211
538
Invalid Matrix dimensions for addition. Cannot add
matrix of dimensions 3 with 3x2

C:/matrix1.txt
C:/matrix2.txt

matrix1.txt :
948
237
921
matrix2.txt :
123
456
1?3

INVALID INPUT

C:/matrix1.txt
C:/matrix2.txt

matrix1.txt:
abc
def
ghi
matrix2.txt:
285
852
024

INVALID INPUT

Problem 5
Statement: Develop a program to find simple interest and compund interest for a given principal
amount, rate and tenure. Program should accept the user input using commmand line arguments.
In case of a bad input, program should output appropriate message as mentioned in output
specification below. (Interest Calculator)
Information: Simple interest is interest paid only on the original principal, not on the interest
accrued Simple interest is determined by multiplying the interest rate by the principal by the
number of periods. When the interest rate is applied to the original principal and any accumulated
interest, this is called compound interest.
Simple interest is calculated using the formula SI=PxNxR
Compound interest is calculated using the formula CI = {[P * (1+(R/100))^N] - P}
where, P = Principal Amount, N=Tenure in years and R=Rate of interest per annum,where N>0 &
P>0
Input Format
Line 1 Principal amount
Line 2 Rate of interest per annum Line 3 Tenure (in years)
Output Format
Line 1 For Valid input
Simple Interest:
where value is simple interest rounded upto 2 digits
For Invalid input
Invalid Input

Line 2 Compound Interest:


where value is compound interest rounded upto 2 digits,
followed by a new line
Sample Inputs and Outputs

Sr.No
1

Input
5000
8
2

Output
Simple Interest: 800.0
Compound Interest: 832.0

16000
0
8
-7856
3
6
1000
12.256
3
5680
10.67
?

Simple Interest: 0.0


Compound Interest: 0.0

8964
14
0

Invalid Input

Invalid Input

Simple Interest: 367.68


Compound Interest: 414.58
Invalid Input

TCS CodeVita 2015 Round1 Question

Reverse Gear

Credit and Risk Calculator

Accico Equi Pairs

Drunkard's Walk

Minimum Distance

Recurring Deposit

Earthquake Damage Estimator


CodeVita
TCS CodeVita 2015 Round2 Question

Alpha Numeric Sorting

MF Tracker

TestVita

ISL Schedule

Find Captures

Romeo and Juliet

TCS CodeVita 2014 Questions


CodeVita

TCS CodeVita 2014 Round1 Question

Super ASCII String Checker

Zombie World

Stone Game - One Four

Trace the Rats

Online Communities - Even Groups

Matrix Rotations

Compiler Design - Limit the Method Instructions

Compiler Design - Limit the Method Instructions


CodeVita

TCS CodeVita 2014 Round2 Question

Valid Segments

Close Strings

Employee DB Design

Employee Hierarchy

Close Friends

Cyclic Palindrome

TCS CodeVita 2013 Questions


CodeVita

TCS CodeVita 2013 Round1 Question

Sequence (Longest Progressive Sequence)

Zombie World

Jumble With Numbers

Game of Primes
CodeVita

TCS CodeVita 2013 Round2 Question

Query Engine

Loan Structuring

Expense Solver

Pagination

Credits

Count The Factor

Isotope Fusion

Brokerage

Profit or Loss statement for Transactions

Helloworld

Hexogonal Triangle

Vous aimerez peut-être aussi