Professional Documents
Culture Documents
Programming MCQs
Published on 07 Mar 2020
TCS Programming questions (MCQs) are discussed here with solutions. These TCS
programming MCQs were asked in the latest TCS drive. So practicing these can help you answer
a lot of questions in the TCS drive. Checkout latest TCS off campus drive details here.
Programming Concepts:
Iteration, recursion, procedural vs OOP.
C Language: call by value/reference, basic and derived data types, storage class, scope and
visibility, basics of pointers, basic header files, library functions, branching and
looping, command line arguments, user-defined functions.
Algorithms:
Basic search algorithms, basic sort algorithms (tree traversal, dynamic programming, etc)
Data Structures:
Array, Stack, Queue, List (tree, hash table, etc)
TCS has officially released a list of indicative question types asked in TCS Programming Mcqs
section. The following are the expected question types for this section.
Given a code in C language/pseudo-code, Identify the functionality of the code.
Given a code in C language/pseudo-code, identify the bug (syntactic/ semantic)
in the code.
Conceptual Questions in programming
Elementary algorithms based questions
Elementary data structures based questions
Questions based on basics of C language
Basic Concepts behind compiling, linking, OS
Note: Coding using Command Line Arguments is not mandatory in TCS exam. However, you
may expect some programming MCQs based on command line Arguments. Click here to
understand Command Line Arguments better
1) Eesha was in a wonderland where she saw a treasure trove of seven items of various items (in
lakhs) and weights (in kgs) as per the table given below.
Value Weight
12 4
10 6
8 5
11 7
14 3
5 10
5 12
She wanted to bring back the maximum value of items but she was not able to carry more than
10 kgs. Using dynamic programming, what is the maximum value of the items that she could
carry back with her.
Answer: 25
2) In C language, if a function return type is not explicitly defined then it defaults to what data
type?
Answer: Int
7) Eesha wants to implement an image viewer application to view images in a given folder. The
application will be able to display an image and will also know what its next and previous
images are at any given point of time so that the user can so that the user can view next/previous
image by pressing right/left keys on the keyboard. Which data structure is appropriate for Esha to
use?
a) Tree
b) Queue
c) Linked list
d) Stack
Answer: Linked list
8)The pseudo code below sorts an array using bubble sort. Here A is the array and the n is the
number of elements in it. Function swap exchanges the value of 2 given value.
This function is called with A and 7 as parameter where the array initially contains the element
64, 34, 25,12, 22, 11, 9
a) 34 25 12 22 11 9 64
b) 25 12 22 11 9 34 64
c) 11 9 12 22 25 34 64
d) 12 11 9 22 25 34 64
Answer: 25 12 22 11 9 34 64
9) #define is used to
a) Define a variable
b) Define a macro
c) Define a function
d) Define a constant
Answer: Define a macro
12) Eesha is developing a word processing software in which she wants to provide undo feature.
The software will maintain all the sequential changes and at any point of time pressing control z
will undo the latest change, what data structure should Eesha use for this?
a)Stack
b)Queue
c)Linked list
d) Array
Answer: Stack
13) #include
Main(intargc,char**argv)
{
printf(%sn,argv[--argc]);
Return 1;
}
The above program was run with the following command line parameters
Asha usha nisha easha
What was the output?
a) Nisha
b) Unable to run due to compilation error
c) No output, runtime error
d) easha
Answer: easha
STEP by STEP guide to solving the coding section in TCS NQT 2020.
STEP 1: Understanding the story.
You are given 30 minutes to write a program and clear all the test cases. Of this, spend
the first five to six minutes on understanding the story given and figuring out what needs
to be calculated.
If your English is not very strong, you need to spend more time in reading and
understanding the task. Don’t jump into typing your program before you understand
what is going on.
These are the points that you need to understand from the task.
There are coins of several denominations.
Initially, there are an Even number of coins of each type.
One of the coins is lost. When you remove 1 from an even number, we get an Odd
number. So, finally we have many denominations occurring an Even number of times
but one particular denomination occurring an Odd number of times.
The first input we get is the total number of coins. Let’s call this N.
In the second line we get only N-1 values because one of the coins is missing.
The output is the denomination (value) of the missing coin.
STEP 2: Reading the inputs
Once you know what is needed, we need to think in terms of how you write the code. At
this time we don’t know how to find the answer. But we know how to take the inputs. So,
the first part of the program is to read the value of N, declare an array and read N-1
values into the array.
Even though the task keeps changing, reading a set of values in a loop is required in
many programs. You will need to practice several programs so that you won’t waste
your time in simple tasks like this in the actual exam.
STEP 3: Cracking the core logic.
The next step is to figure out how to convert this data into an answer. By the time we
reach this step in the exam, we should have about 20 minutes left.
A^B^C^B^A^C = 0
So, if we perform the EXOR operation on a series of numbers we will notice some
interesting results.
If a particular number (say A) is occurring an Even number of times, the EXOR of all of
them together is 0. i.e. A^A^A…^A =0 when the number is occurring an Even number of
times.
If a number is occurring an Odd number of times, the EXOR of all the occurrences is
same as the number itself. So, A^A^A^….^A= A when the number is occurring an Odd
number of times.
The order in which we apply the EXOR operation doesn’t matter A^B=B^A.
Using these properties together, we can notice that when we take the EXOR of all the
inputs, any number that occurs an even number of times will give an EXOR of 0. If A is
the number that occurs an Odd number of times, the overall EXOR for all its
appearances will be equal to A. The overall result for all the other numbers will be zero.
So, finally we get A^0 which is equal to A.
Once we know this, we can go ahead and implement this in the code.
We just need to take a temporary variable to store the result. Let’s call this E and
initialize it to 0. We then need to go through a loop and perform EXOR on all the given
elements. The final value of EXOR is the answer we need.
Do I need to make my program so efficient?
While it is always good to write efficient programs you need to control your greed.
Before you worry about efficiency, you need to ensure that your program clears at least
some of the test cases. Finally, nobody reads your code – they just look at the number
of test cases. Make sure that your code clears as many test cases as possible.
However, if you know an efficient method, there is no reason for you to not use it. Go
ahead, give it best shot. This is your playground.
In which language should I write the code?
The advantage of choosing C, C++ and Java over scripting languages is that the
compiler is very strict. The probability of any mistakes being found by the compiler is
very high which means the probability of validating against the test cases is also high.
On the other hand, in scripting languages like Python or Perl the probability of finding
mistakes by compiler is not fruitful. Some of your coding mistakes might percolate till the
time you go into the compiler stage.
As we keep telling, don’t try to learn a new programming language now. Stick with a
language that you already know. Build your confidence by practicing multiple tasks
using it.
Visit this page for TCS NQT Quantitative
TCS NQT Quantitative Questions
Solve more questions on our TCS NQT Quants Dashboard
Question 1.
1. Advanced: In how many ways can we give change for rs 100 using 1 rupee and 2 rupee
coins? For example for 5 rs we can give three ways(1,1,1,1) (1,1,1,2) )(,1,2,2)
Answer: 51
Question 10
Advanced:
In how many ways can we give change for 100 using 1 rupee and 2 rupee coins? For
example for 5 rs, we can give in three ways : (1,1,1,1,1) (1,1,1,2) (1,2,2)
Answer: 51
Question 11
Advanced: In the figure shown, a triangle is divided into nine strpes of equal height each
parallel to the same side of the triangle. The shaped stripes have a total area of 135 square
units. What is the area of the triangle in square units.
Answer: 243
Question 12
In the IT department of backrub, the administrator password is changed every month. The
team of administrator, spread across the globe, receive an 8 digits number via email. This
number is to be prefixed with a single digit number and suffixed with a single digit number to
get the actual password. The password is divisible by 11 and 8. If the team received
54218345 this month. Then which of the following pairs give valid prefix and suffix
respectively?
a. 3,7
b. 1,6
c. 2,4
d. 4,2
Answer: 1,6
Question 13
13. In the diagram below, the areas of the triangles are as follows: A1=1024, A2=1016,
A3=1057. What is the area of A4?
a. 1032
b. 1036
c. 1020
d. 1065
Answer: 1065
Question 14
14. The people of the land of unsymmetrix to ensure that there is very little symmetry in life.
Even their unit of length (no one knows what it is) is called as unsym. It is their pride that the
front wheel and the real wheels of their bikes are of different sizes but are made so that they
will not slip on the road . In a certain model of bike the radius of the front wheel is 28
unsyms and that of the back wheels is 14 unsyms after driving a certain distance if front
wheel had revolution 54 times how many revolution would the back wheel have undergone?
a. 136
b. 122
c. 108
d. 94
Answer: 108
Question 15
15. Rs. 3000 is distributed among A, B and C such that A gets 2/3rd of what B and C
together get and C gets ½ of what A and B together get. Find C’s share.
a. 1500
b. 1000
c. 1200
d. 1800
Answer: 1000
Question 16
16.
Given that 1 < a< b< c< d, Which of the following is largest ?
In this question , x^y stands for x raised to the power of y. For example , 2^3=8 and 4^1.5=8
exp(x) is e (approx 2.7183) raised to the power x. Thus exp(2.303) is approximately 10.
Answer: exp(c^d)/exp(a^b)
Question 17
17. 32 times of a two digit number is 23 times the number obtained by reversing its digit.
The sum of its digit is 15 Find the number:
a. 96
b. 69
c. 87
d. Insufficient information
Answer: 69
Question 18
18. Let N be the greatest number that will divide 148, 246 and 623 leaving remainders 4, 6
and 11 respectively. What is the remainder if N is divided by 7?
a. 0
b. 1
c. 5
d. 6
Answer: 5
Question 19
19. A store is selling a jacket on sale at 30% off the marked price. A matching pair of pants
is on sale at 40% off the marked price. If the marked price of the pants is Rs. 8500 less than
the marked price of the jacket and the total sale price of both items is Rs. 23500, then what
is the marked price of the jacket?
a. 21700
b. 21800
c. 22000
d. 22100
Answer: 22000
Question 20
Initially, when Sona and Tina left for a shopping expedition , Sona had three times the
money than Tina had. They bought things amounting to Rs. 480 altogether, out of which
Tina’s share was 65%. At the end of shopping, Sona was left with 4 times the amount that
Tina had. What was the amount with Tina at the beginning?
a. 1080
b. 1248
c. 768
d. 936
Answer: 1080
Question 21
A semcircle is drawn on one of the sides of the square with the side of the square as the
diameter of the circle. It the length of the side of the square is 2 What is the radius of the
smallest circle that can contain this figure?
. A power source
. A resistor R and
. Three paraIlelIy connected resistors each of value 3R.
All these connected In series. If the current flowing through the circuit is five amperes, what
will be its value, if R Is doubled and each of 3R is halved?
Answer: 4 amps
Question 27
Ms Thkonapr*ya wants to decorate her abode’s frontage with a triangular lawn. The two
sides of this lawn are of five and sIx meters, subtending an angle of 30 degrees. If the Lawn
maintainer charges Rs.10 per square meter. how much would Trlkonaprlya pay to him for
the entire lawn? You answer should contain only the numeric value.
Answer: 75
Question 28
8haskar wanted to send some documents to Shakuntala He had her address without the 6-
digit pin code. He didn’t want to risk sending documents without pin code. So. he called
Shakuntala. She did not give the pin code directly, she said. The first four digits are 1910 in
hexadecimal and the last four digits are 3177 in octal”. Bhaskar could courier the
documents now. What is her pin code?
Answer: 641683
Question 29
If it takes 10 3D printers 10 minutes to print 10 models, how long will It take 100 printers to
print 100 models?
Fill the correct answer in minutes.
Answer: 10minutes
Question 30
Eighty cricket balls have been packed equally Into two bags A and B. 20 of these bails have
been signed by Kapii Dcv - some of the signed balls are in bag A and the rest in bag B. One
bag ¡s selected and a ball is randomly picked from that Given that the bal is signed, the
pobabllity that It ¡s from Bag B is computed to be 44. If bag A is twice more likely to be
selected than Bag B. how many of the signed bails are in Bag B?
Answer: 16