TCS NQT Coding Questions (2022)

Hello folks, Are you looking for TCS NQT coding questions? You are on the right page. In this blog post, we will see some good TCS coding questions.

About TCS NQT

TCS NQT is an exam conducted by TCS(Tata Consultancy Services) to hire for the role of TCS Ninja and TCS Digital. All the interested students can find the detailed TCS NQT Syllabus and Exam pattern in this article. Nearly 1 million (10 Lakh+) candidates appear in the TCS NQT test every year.

TCS NQT Syllabus and Exam Pattern 2022

TCS NQT Eligibility Criteria

Qualification – B.E/B.Tech/M.E/M.Tech/MCA/M.sc Students

Percentage Criteria- 60% in X/XII/Diploma/UG/PG

Backlogs- 1 Active Backlog

Academic Gap- Maximum two years of Gap allowed.

TCS NQT Important Note

  1. No negative marking
  2. Previously answered questions cannot be revisited
  3. Questions cannot be skipped
  4. Rough paper and calculator will be available on the screen
  5. Each questions needs to be solved within the given time

TCS NQT Exam pattern

SectionQuestionsDuration(Mins)
Numerical Ability2640
Reasoning Ability3050
Verbal Ability2430
Programming Logic1015
Coding 1115
Coding 2130

TCS NQT Coding Questions

Problems on Arrays

  • Find the smallest number in an array
  • Find the largest number in an array
  • Second Smallest and Second Largest element in an array
  • Reverse a given array
  • Count frequency of each element in an array
  • Rearrange array in increasing-decreasing order
  • Calculate sum of the elements of the array
  • Rotate array by K elements – Block Swap Algorithm
  • Average of all elements in an array
  • Find the median of the given array
  • Remove duplicates from a sorted array
  • Remove duplicates from unsorted array
  • Adding Element in an array
  • Find all repeating elements in an array
  • Find all non-repeating elements in an array
  • Find all symmetric pairs in array
  • Maximum product subarray in an array
  • Replace each element of the array by its rank in the array
  • Sorting elements of an array by frequency
  • Rotation of elements of array- left and right
  • Finding equilibrium index of an array
  • Finding Circular rotation of an array by K positions
  • Sort an array according to the order defined by another array
  • Search an element in an array
  • Check if Array is a subset of another array or not

Problems on Numbers

  • Check if a number is palindrome or not
  • Find all Palindrome numbers in a given range
  • Check if a number is prime or not
  • Prime numbers in a given range
  • Check if a number is armstrong number of not
  • Check if a number is perfect number
  • Even or Odd
  • Check weather a given number is positive or negative
  • Sum of first N natural numbers
  • Find Sum of AP Series
  • Program to find sum of GP Series
  • Greatest of two numbers
  • Greatest of three numbers
  • Leap Year or not
  • Reverse digits of a number
  • Maximum and Minimum digit in a number
  • Print Fibonacci upto Nth Term
  • Factorial of a number
  • Power of a number
  • Factors of a given number
  • Print all prime factors of the given number
  • Check if a number is a strong number or not
  • Check if a Number is Automorphic
  • GCD of two numbers
  • LCM of two numbers
  • Check if a number is Harshad number
  • Check if the number is abundant number or not
  • Sum of digits of a number
  • Sum of numbers in the given range
  • Permutations in which N people can occupy R seats in a classroom
  • Program to add two fractions
  • Replace all 0s with 1s in a given integer
  • Can a number be expressed as a sum of two prime numbers
  • Calculate the area of circle
  • Program to find roots of a Quadratic Equation

Problems on Number System

  • Convert Binary to Decimal
  • Convert binary to octal
  • Decimal to Binary conversion
  • Convert decimal to octal
  • Convert octal to binary
  • Convert octal to decimal
  • Convert digits/numbers to words

Problems on Sorting

  • Bubble Sort Algorithm
  • Selection Sort Algorithm
  • Insertion Sort Algorithm
  • Quick Sort Algorithm
  • Merge sort algorithm

Problems on String

  • Check if a given string is palindrome or not
  • Count number of vowels, consonants, spaces in String
  • Find the ASCII value of a character
  • Remove all vowels from the string
  • Remove spaces from a string
  • Remove characters from a string except alphabets
  • Reverse a String
  • Remove brackets from an algebraic expression
  • Sum of the numbers in a String
  • Capitalize first and last character of each word
  • Calculate frequency of characters in a string
  • Find Non-repeating characters of a String
  • Check if two strings are anagram of each other
  • Count common sub-sequence in two strings
  • Check if two strings match where one string contains wildcard characters
  • Return maximum occurring character in the input string
  • Remove all duplicates from the input string.
  • Print all the duplicates in the input string.
  • Remove characters from first string present in the second string
  • Change every letter with the next lexicographic alphabet in the given string
  • Write a program to find the largest word in a given string.
  • Write a program to sort characters in a string
  • Count number of words in a given string
  • Write a program to find a word in a given string which has the highest number of repeated letters
  • Change case of each character in a string
  • Concatenate one string to another
  • Write a program to find a substring within a string. If found display its starting position
  • Reverse words in a string

Some more TCS coding questions

TCS coding question 1

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 is 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 the value of the nth 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.

#include”stdio.h”
#include”math.h”
int main()
{
  int n;
  scanf(“%d”, &n);
  if(n % 2 == 1)
  {
    int a = 1;
    int r = 2;
    int term_in_series = (n+1)/2;
    int res = pow(2, term_in_series – 1);
    printf(“%d “, res);
  }
  else
  {
    int a = 1;
    int r = 3;
    int term_in_series = n/2;
    int res = pow(3, term_in_series – 1);
    printf(“%d “, res);
  }
  return 0;
}
Input: 16
Output: 2187

TCS coding question 2

Consider the following series: 0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8
This series is a mixture of 2 series all the odd terms in this series form even numbers
in ascending order and every even term is derived from the previous term using the
formula (x/2).


Write a program to find the nth term in this series.
The value n is 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 the value of the nth term no other characters /strings or message should be written to STDOUT.
For example, if n=10, the 10th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.
You can assume that the ‘n’ will not exceed 20,000.

#include “stdio.h”
#include “math.h”
int main()
{
  int n;
  scanf(“%d”, &n);
  if(n % 2 == 1)
  {
    int a = 1;
    int r = 2;
    int term_in_series = (n+1)/2;
    int res = 2 * (term_in_series – 1);
    printf(“%d “, res);
  }
  else
  {
    int a = 1;
    int r = 3;
    int term_in_series = n/2;
    int res = term_in_series – 1;
    printf(“%d “, res);
  }
  return 0;
}
Input: 10
Output: 4

TCS coding question 3

Write a c program, to check whether the given year is a leap year or not using command line arguments. A leap year is a calendar year containing one additional day (Feb 29th) added to keep the calendar year synchronized with the astronomical year.

#include<stdio.h>
int main(int a, char*b[])
{
  int year; year=atoi(b[1]);
  if(year%100==0)
  {
    if(year%400==0)
    {
      printf(“LEAP YEAR”);
    }
    else
#include<stdio.h>
int
main (int a, char *b[])
{
  int year;
  year = atoi (b[1]);
  if (year % 100 == 0)
    {
      if (year % 400 == 0)
	{
	  printf (bLEAP YEAR b );
	}
      else
	{
	  printf (bNOT LEAP YEAR b );
	}
    }
  else if (year % 4 == 0)
    {
      printf (bLEAP YEAR b );
    }
  else
    {
      printf (bNOT LEAP YEAR b );
    }
  return 0;
}

TCS coding question 4

Write a c program, to find the GCD of the given 2 numbers, using command line arguments. The input is 2 integer and the output GCD also should be an integer value.

#include<stdio.h>
int main(int x, char *y[])
{
int a,b,small,i;
a=atoi(y[1]);
#include<stdio.h>
int
main (int x, char *y[])
{
  int a, b, small, i;
  a = atoi (y[1]);
  b = atoi (y[2]);
  small = a > b ? b : a;
  for (i = small; i >= 1; i b )
    {
      if ((a % i == 0) && (b % i == 0))
	{
	  printf (b%d b , i);
	  break;
	}
    }
  return 0;
}

TCS coding question 5

Write C Program to check whether a given number is a prime number or not. The given number N, a positive integer, will be passed to the program using the first command line parameter. If it is a prime number the output should be the square root of the number up to 2 decimal point precision, If it is not a prime number then print 0.00 to stdout.

#include<stdio.h>
#include<math.h>
int
main (int a, char *b[])
{
  int number, i, flag = 1;
  number = atoi (b[1]);
  for (i = 2; i < number; i++)
    {
      if (number % i == 0)
	{
	  flag = 0;
	  break;
	}
    }
  if (flag == 1)
    printf (b%.2f b , sqrt (number));
  else
    printf (b0.00 b );
  return 0;
}

TCS coding question 6

C Program to check whether a given number is a strong number or not. The given number N, a positive integer, will be passed to the program using the first command line parameter. If it is a strong number, the output should be “YES”, If it is not a prime number then the output should be “NO” to stdout. Other than YES or NO, no other extra information should be printed to stdout.

#include<stdio.h>
#include<math.h>
int
main (int a, char *b[])
{
  int number, i, temp, sum = 0, factorial = 1;
  number = atoi (b[1]);
  temp = number;
  while (number != 0)
    {
      int rem = number % 10;
      for (i = 2; i <= rem; i++)
	{
	  factorial = factorial * i;
	}
      sum = sum + factorial;
      number = number / 10;
      factorial = 1;
    }
  if (temp == sum)
    printf (bYES b );
  else
    printf (bNO b );
  return 0;
}

TCS coding question 7

Write a C program that will convert a given decimal integer number N to its binary equivalent. The given number N, a positive integer, will be passed to the program using the first command line parameter. Print the equivalent binary number to stdout. Other than the binary number, no other extra information should be printed to stdout Example: Given input “19”, here N=19, expected output 10011.

#include<stdio.h>
#include<math.h>
int
main (int a, char *argv[])
{
  int number, count, i;
  int b[32];
  number = atoi (argv[1]);
  count = 0;
  while (number != 0)
    {
      b[count] = number % 2;
      number = number / 2;
      count++;
    }
  for (i = (count - 1); i >= 0; i b )
    printf (b%d b , b[i]);
  return 0;
}

TCS coding question 8

Write a c program that will find the sum of all prime numbers in a given range. The range will be specified as command-line parameters. The first command line parameter, N1 which is a positive integer, will contain the lower bound of the range. The second command line parameter N2, which is also a positive integer will contain the upper bound of the range. The program should consider all the prime numbers within the range, excluding the upper bound and lower bound. Print the output in integer format to stdout. Other than the integer number, no other extra information should be printed to stdout. Example Given inputs “7” and “24” here N1= 7 and N2=24, the expected output is 83.

#include<stdio.h>
int
main (int argc, char *argv[])
{
  int N1, N2, j, i, count, sum = 0;
  N1 = atoi (argv[1]);
  N2 = atoi (argv[2]);
  for (i = N1 + 1; i < N2; ++i)
    {
      count = 0;
      for (j = 2; j <= (i / 2); j++)
	{
	  if (i % j == 0)
	    {
	      count++;
	      break;
	    }
	}
      if (count == 0)
	sum = sum + i;
    }
  printf (b%d b , sum);
  return 0;
}

TCS coding question 9

Write a C program to check whether the given number is a perfect square or not using command line arguments.

#include<stdio.h>
#include<math.h>
int
main (int a, char *b[])
{
  int n, i;
  n = atoi (b[1]);
  for (i = 0; i <= n; i++)
    {
      if (n == i * i)
	{
	  printf (bYES b );
	  return 0;
	}
    }
  printf (bNO b );
  return 0;
}

TCS Coding question 10

Write a C program to check whether the given number is Palindrome or not using command line arguments.

#include<stdio.h>
#include<math.h>
int
main (int a, int *b[])
{
  int number, rem, sum = 0;
  number = atoi (b[1]);
  int copy = number;
  while (number != 0)
    {
      rem = number % 10;
      sum = sum * 10 + rem;
      number = number / 10;
    }
  if (copy == sum)
    printf (bPalindrome b );
  else
    printf (bNot Palindrome b );
  return 0;
}

Thanks for reading!

Leave a Comment