# TCS NQT Programming Questions with Answers 2021

Hope you are doing great! This post will basically clear all your queries with regards to the TCS NQT Programming Section 2021. We will cover TCS NQT 2020 and past TCS NQT Programming questions along with explanations.

Firstly, let me brief you about TCS NQT (national qualifier test) 2021. Basically, TCS National Qualifier Test (TCS NQT) is a multi-level assessment to assess the following competencies and skills. TCS NQT is an Ability Test that assesses your competencies and skills.

Secondly, each student who completes the TCS National Qualifier Test (TCS NQT) gets an NQT Score. The NQT (Cognitive Skills) Score is applicable for all industries and job roles. You can also refer to TCS NQT Syllabus

What should I study for TCS Subject NQT

In Coding Section, you need to study Operators, Looping statements, Control statements, Arrays, Strings, Functions, Object-Oriented Programming (OOPS), Fibonacci Series, Data Structures: Linked List-(Single, Double), Stack, Queue, Trees(BT, BST) and Graphs, Pseudocoding, Algorithms, and Basic Software Development Cycle.
For Coding, you will have to practice and study Data types, Operators, Arrays, Strings, Decision Making, Looping, Functions, and Scenario-based questions. This section consists of coding MCQ mainly from C, C++, and a few from data structures and algorithms.

## TCS NQT Programming Section-Overview

Now, let me explain to you about the coding section. This section includes 10 programming MCQs to be completed in 15 minutes.

The next section includes 2 hands-on questions that should be completed in 45 minutes. Languages allowed are C/ C++/ Java/ Python/ PERL. To gain max opportunities of cracking this section, you must try to clear all of the possible test cases. GeeksToCode is here to make sure that you qualify with flying colors in this section.

Which programming language should I chose for TCS Subject NQT?

First and foremost, you should select a programming language that you are more comfortable with. C programming and python are most common. The TCS compiler takes 5 seconds to compile. Thus, one must avoid compiling the program multiple times. As it just leads to loss of time.

## TCS NQT Programming questions – Important instructions

1. 15 minutes are given to solve 10 MCQs
2. First hands-on question-15 minutes and the second question 30 minutes.
3. Choice of C / C++ / Java / Perl / Python 3.
4. Provided an IDE to debug.
5. The input to the program either through STDIN / Command line arguments, as it is specified.
6. The program should write the output to STDOUT.
7. The result will be based on the public and private test cases based on the evaluation.

Also, while printing the output there should be no leading or trailing spaces printed. Make sure no other text should be printed other than the required output. If the output is a number, you should not print any sign unless it is a negative.
number. There should be no scientific notation (3.9265E + 2). All floating-point numbers must contain that many decimal places as mentioned in
the question.

For coding, there is only one tip, try to solve the pattern problem with at least 2 logic within an average of an hour, it seems a little bit difficult but once you mug up the habit of doing this before your exam, no one stops you from clearing the exam!

“Don’t be afraid to give up the good to go for the great.”

–John D. Rockefeller

## TCS Coding Programming Questions 2019-2020

1. Property which allows to produce different executable for different platforms in C is called?

A. File inclusion                                            B. Selective inclusion

C. Conditional compilation                          D. Recursive macros

Explanation: Conditional compilation is the pre-processor facility to produce different executable.

2. C preprocessors can have compiler specific features.

A. true                                               B. false

C. Depends on the standard         D. Depends on the platform

3. Preprocessor feature that supply line numbers and file names to compiler is called?

A. Selective inclusion                                    B. macro substitution

C. Concatenation                                          D. Line control

4. Which of the following are C preprocessors?

A. #ifdef                                            B. #define

C. #endif                                           D. All of the mentioned.

5. The C pre-processors are specified with _________symbol.

A. #                                      B. \$

C. ” ”                                    D. None of the mentioned.

6. What is the output of this C code?

``````#define a 20
int main() {
const int a = 50;
printf("a = %d\n", a);
}
``````

A. a = 50                                            B. a = 20

C. Run time error                            D. Compilation Error

Explanation: The #define substitutes a with 20 leaving no identifier and hence compilation error.

7. What is the output of this C code?

``````int main() {
int var = 010;
printf("%d", var);
}
``````

A. 2                       B. 8                       C. 9                       D. 10

Explanation: 010 is octal representation of 8.

8. enum types are processed by?

A. Compiler        B. Pre-processor              C. Linker              D. Assembler

9. What is the output of this C code?

``````int main() {
printf("AllIndiaExams\r\nclass\n");
return 0;
}
``````

A. AllIndiaExamsclass                                    B. AllIndiaExamsclass

C. classundry                                                 D. AllIndiaExams

Explanation: rn combination makes cursor move to nextline.

10. What is the output of this C code?

``````int main() {
const int a;
a = 32;
printf("a is %d", a);
return 0;
}
``````

A. a is 32                                                          B. Compile time error

C. Run time error                                           D. none

Explanation: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

## TCS NQT Programming Hand-On Questions

Here is a list of coding questions with answers that were asked in past TCS NQT exams. Make sure you go through these during your TCS NQT preparation. You must remember to study and practice these programming questions. This will not only boost your conviction but also will be helpful to answer them quickly. The questions will mainly cover subjects like arrays, string, linked list, Fibonacci series, and so on.

### Candies Problem

Q1.There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when a JAR is full. At any point in time. JAR can have M number of Candies where M<=N.

Candies are served to the customers. JAR is never remained empty as when last k candies are left. JAR if refilled with new candies in such a way that JAR gets full.
Write a code to implement the above scenario.

Display JAR at the counter with an available number of candies. Input should be the number of candies one customer can order at the point in time. Update the JAR after each purchase and display JAR at the Counter.

Output should give number of Candies sold and updated number of Candies in JAR.

If Input is more than candies in JAR, return: “INVALID INPUT”

Given,  N=10, where N is NUMBER OF CANDIES AVAILABLE

K =< 5, where k is number of minimum candies that must be inside JAR ever.

Example 1:(N = 10, k =< 5)

Input Value: 3

Output Value: NUMBER OF CANDIES SOLD : 3

NUMBER OF CANDIES AVAILABLE : 7

Example : (N=10, k<=5)

Input Value : 0

Output Value: INVALID INPUT

NUMBER OF CANDIES LEFT : 10

Code:

``````total_candies = 10
no_of_candies = int(input())
if no_of_candies in range(1, 6):
print('No. of Candies Sold:',no_of_candies)
print('No. of Candies Left:',total_candies-no_of_candies)
else:
print("Invalid Input")
print('No. of Candies Left:',total_candies)``````

### Number Series with a Twist 2

Q2.Consider the following series: 1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, 64, 729, 128, 2187 …

This series is a mixture of 2 series – all the odd terms in this series form a geometric series and all the even terms form yet another geometric series. Write a program to find the Nth term in the series.

The value N in a positive integer that should be read from STDIN. The Nth term that is calculated by the program should be written to STDOUT. Other than value of n th term,no other character / string or message should be written to STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value 2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

Code:

``````n = int(input('enter the number: '))

a= 1

b= 1

for i in range(1, n+1):

if(i%2!=0):

a = a*2

else:

b = b*3

if(n%2!=0):

print('\n{} term of series is {}\t'.format(n,a/2))

else:

print('\n{} term of series is {}\t'.format(n,a/2))``````

### Forward-Backward Problem

Q3. Consider one string as input. You have to check whether the strings obtained from the input string with single backward and single forward shifts are the same or not. If they are the same, then print 1, otherwise, print 0.

Hint: Backward shift: A single circular rotation of the string in which the first character becomes the last character and all the other characters are shifted one index to the left. For example, “abcde” becomes “bcdea” after one backward shift.

Forward shift: A single circular rotation of the string in which the last character becomes the first character and all the other characters are shifted to the right. For example, “abcde” becomes “eabcd” after one forward shift.
Instructions:* The system does not allow any kind of hard-coded input values.* The written program code by the candidate will be verified against the inputs that are supplied from the system.* For more clarification, please read the following points carefully till the end.

Constraints: String str should not allow space, special characters, and numbers. String str should only be in the English language.
Input / Output:
Input: sfdlmnop Output:0
Explanation: In the first example, the string is “sfdlmnop”

Forward shift: fdlmnops

Backward shift: psfdlmno

Both the strings above are not equal so the output is 0.

``````if __name__ == "__main__":
str = input().strip()
s1 = str[1:] + str[:1]
s2 = str[-1:] + str[:-1]
if s1 == s2:
print(1)
else:
print(0)``````

For similar kind of questions do refer our article on TCS NQT basic coding questions

## Homework Questions

Here is a list of questions you must try to solve on your own-

Q1. Write a program to sort numbers in an array and print the numbers with
alternate digits. Use malloc() to get the input array.
Ip: {4,2,5,3,7}
Op: {2,4,7}

Q2.Write a C program that will check whether a given year YYYY is a leap year. A
leap year is exactly divisible by 4 except for century years(years ending with 00).
The century year is a leap year only if it’s perfectly divisible by 400.

Q3.To print the trapezium pattern. for example, we have n=4 the output should be like

1*2*3*4*17*18*19*20

—5671415*16

– – -8912*13

– – – 10*11

Q4. Write a program to print the not common numbers in both the arrays.
Input: Arr1 = {1,2,3,4}
Arr2= {4,5,6,7}
Length = 4
Length = 4
Output: 6

Q5. Test whether an input string of opening and closing parentheses was balanced
or not. If yes, return the no. of parentheses. If no, return -1.

Input: “(( ))”
Output: 2
Input: “()(“
Output:-1

## Conclusion

Hope you loved TCS NQT Programming questions, feel free to comment and share.