TCS codevita old questions for practice

Here this list of the TCS codevita questions.The list starts from simple questions and gets tougher. These are the useful questions that can be used to practice for TCS codevita paper. Lets start with the questions.

Here this list of the TCS codevita questions.The list starts from simple questions and gets tougher. These are the useful questions that can be used to practice for TCS codevita paper. Lets start with the questions.

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.No Input Input In File Output 1 C:/sort.txt sort.txt : 1,2,3,2,3,1,3,1,3 Values Before the sort: 1 2 3 2 3 1 3 1 3 Values after the Ascending sort: 1 1 1 2 2 3 3 3 3  Values after the Descending sort: 3 3 3 3 2 2 1 1 1 2 C:/sort.txt sort.txt : 0,0.001,0.01,0.0001,0.0001,0.0000001 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 3 C:/sort.txt sort.txt : 2,3,2,a,b,3 Invalid Input 4 C:/sort.txt sort.txt : 2,3,3,? 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 From Number, say N1
Line 2 To Number, say N2
Line 3 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 1 15 6 13 2 5 1000 94 503 3 1 15 9 No prime number is present at this index 4 59 96 0 Invalid Input 5 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 newline character
Columns within each row are space delimited
e.g. A 3x3 matrix will be represented in the file as :
1 2 3
4 5 6
7 8 9

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 Input Input In File Output 1 C:/matrix1.txt C:/matrix2.txt matrix1.txt : 3 3 1 5 9 2 6 4 2 matrix2.txt:  2 1 1 1 5 5 3 8 9 Input Matrix 1 : 3 3 1 5 9 2 6 4 2 Input Matrix 2 : 2 1 1 1 5 5 3 8 9 Valid Matrix dimensions for addition. 5 4    2 6 14  7 9 12 11 2 C:/matrix1.txt C:/matrix2.txt matrix1.txt :  7 3 1 7 2 5 2 6 4 matrix2.txt : 2 1 1 5 3 8 Input Matrix 1 : 7 3 1 7 2 5 2 6 4 Input Matrix 2 : 2 1 1 5 3 8 Invalid Matrix dimensions for addition. Cannot add matrix of dimensions 3 with 3x2 3 C:/matrix1.txt C:/matrix2.txt matrix1.txt :  9 4 8 2 3 7 9 2 1 matrix2.txt : 1 2 3 4 5 6 1 ? 3 INVALID INPUT 4 C:/matrix1.txt C:/matrix2.txt matrix1.txt: a b c d e f g h i matrix2.txt: 2 8 5 8 5 2 0 2 4 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.

Also read: TCS codevita important questions 2015

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 Input Output 1 5000 8  2 Simple Interest: 800.0 Compound  Interest: 832.0 2 16000 0 8 Simple Interest: 0.0 Compound  Interest: 0.0 3 -7856 3 6 Invalid Input 4 1000 12.256 3 Simple Interest: 367.68 Compound  Interest: 414.58 5 5680 10.67 ? Invalid Input 6 8964 14 0 Invalid Input

Thank you for reading this post.

You may also like: Best answer of tcs codevita 2015 questions BLOGGER

Related Articles

Name

ltr
item
MindxMaster: TCS codevita old questions for practice
TCS codevita old questions for practice
Here this list of the TCS codevita questions.The list starts from simple questions and gets tougher. These are the useful questions that can be used to practice for TCS codevita paper. Lets start with the questions.
https://1.bp.blogspot.com/-iP78-Dvnzn8/VclcaYfHAGI/AAAAAAAAAYo/ZpNv6tNuTrQ/s1600/codevita4.jpg
https://1.bp.blogspot.com/-iP78-Dvnzn8/VclcaYfHAGI/AAAAAAAAAYo/ZpNv6tNuTrQ/s72-c/codevita4.jpg
MindxMaster
https://www.mindxmaster.com/2016/06/tcs-codevita-old-questions-for-practice.html
https://www.mindxmaster.com/
https://www.mindxmaster.com/
https://www.mindxmaster.com/2016/06/tcs-codevita-old-questions-for-practice.html
true
5332415103371288268
UTF-8