TCS NQT Coding Questions and Answers 2020-2021

Latest TCS NQT Coding Questions and Answers

 In this round the interviewer will be testing your coding skills, on the basis of your favorable coding languages and coding techniques which you would have mentioned in the previous round.

Few pointers that you should keep in mind for this round are-:

  • Do not mention any language proficiency in which you are not comfortable in coding.
  • Try to keep your codes simple and concise.
  • Do not get over-confident if the interviewer give you a question which you already know.
  • Try to demonstrate your code with the help of flowcharts and algorithms.
tcs nqt coding interview
Paramters you would be judged upon
1 %
Code
1 %
Simplicity
1 %
Techniques
C programming

Programming questions based on C

Q1- What are different storage class specifiers in C?

Q2- What is the difference between %d and %i ?

 Q3- What is NULL pointer?

Q4- What is enum ?

Q5- What are local static variables?

To practice more sample questions click on the button below

Programming questions based on C++

Q1-What are the differences between references and pointers?

Q2-What are virtual functions ?

Q3- What is this pointer?

Q4- What is Access Specifier in C++?

Q5-What is implicit type conversion ?

To practice more sample questions click on the button below

Java questions

Programming questions based on JAVA

Q1- Give an example of multiple inhertance in java ?

Q2- Does pointers exists in java ?

Q3- How to avoid deadlock in java ?

Q4- What is multithreading ?

Q5- What is exception handling in java ?

To practice more sample questions click on the button below

For studying more coding questions visit our codes page, where we have collected top 100 codes for you to enhance your coding skills

 

Coding Questions in various languages

Swap two numbers without using the third variable

#include <stdio.h> 
int main()
{
    int xy;   
    printf("Input two integers to swap\n");
    scanf("%d%d", &x, &y);
    //logic   
    x = x + y;
    y = x - y;
    x = x - y
    printf("x = %d\ny = %d\n",x,y);
    return 0

To check whether the number is prime or not using recursion

#include<stdio.h>
// declaring the recursive function
int isPrime(intint);
int main()
{
    int numprime;
    printf("Enter number : ");
    scanf("%d", &num);
    prime = isPrime(numnum/2);
    if(prime == 1)
    {
        printf("\n%d is a prime number\n"num);
    }
    else
    {
        printf("\n%d is not a prime number\n"num);
    }
    return 0;
}
// function definition
int isPrime(int nint i)
{
    if(i == 1)
        return 1;   
    else
    {
        if(n%i == 0)
            return 0;
        else
            isPrime(ni-1);    
    }
}

To check whether the year is leap or not

#include <stdio.h>
int checkYear(int year

    if (year % 400 == 0//condition for leap year
        return 1
    if (year % 100 == 0//condition for leap year
        return 0
    if (year % 4 == 0//condition for leap year
        return 1
    return 0

  
int main() 

    int year = 2000
checkYear(year)? printf("Leap Year"): printf("Not a Leap Year"); 
    return 0

Find the factorial of number using recursion

#include <stdio.h>
long int fact(int n);
int main()
{
    int n;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    printf("Factorial of %d = %ld"nfact(n));
    return 0;
}
long int fact(int n)
{
    if (n >= 1)
        return n*fact(n-1);
    else
        return 1;
}

 Calculate the sum of even elements of array

#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int array[n];
    int sum = 0;
    for(int i=0i<ni++)
    {
        scanf("%d",&array[i]);
    }
    for(int i=0i<ni++)
    {
        if (array[i]%2==0)
            sum = sum + array[i];
    }
    printf("%d",sum);
    return 0;
}

Print Fibonacci Series upto n terms

#include<stdio.h>
int main()
{
    //To initialize variables 
    int n1=0,n2=1,n3,limit,i;
    //To take user input
    printf("enter a limit of series \n");
    scanf"%d",&limit);
    printf("Fibonacci series %d %d ",n1,n2);
    //To use this loop for given length
    for(i=2;i<limit;i++)
    {
        //n1 and n2 sum  store in new variable n3
        n3=n1+n2;   
        n1=n2;
        n2=n3;
        //display serious 
        printf("%d ",n3);
    }
    return 0;
}

Program to find the sum of each row of 2d matrix

#include<stdio.h>
int main()
{
    int nm;
    scanf("%d %d",&n,&m);
    int sum = 0;
    int array[n][m];
    for(int i=0i<ni++)
    {
        for(int j=0j<mj++)
        {
            scanf("%d",&array[i][j]);
        }
    }
    for(int i=0i<ni++)
    {
        sum = 0;
        for(int j=0j<mj++)
        {
            sum = sum + array[i][j];
        }
        printf("%d ",sum);
    }
    return 0;
}

Program to Convert Octal number into Binary Number

#define MAX 1000
int main()
{
    char octalnum[MAX];
    //For initialize 
    long i = 0;
    //taking user input of octalnum
    printf("Insert an octal number: ");
    scanf("%s"octalnum);
    printf("Equivalent binary number: ");
    while (octalnum[i])
    { 
       //use switch case for multiple condition
        switch (octalnum[i])
        {
          case '0':
               printf("000"); break;
          case '1':
               printf("001"); break;
          case '2':
               printf("010"); break;
          case '3':
               printf("011"); break;
          case '4':
               printf("100"); break;
          case '5':
               printf("101"); break;
          case '6':
               printf("110"); break;
          case '7':
               printf("111"); break;
         //for invalid case 
          default:
               printf("\n Invalid octal digit %c "octalnum[i]);
               return 0;
        }
        i++;
    }
    return 0;
}

Program to count vowels and consonant in a sentence

#include <stdio.h>
int main()
{
    char str[100];
    scanf("%[^\n]s",str);
    int i = 0;
    int vowels=0consonant=0space=0;
    while(str[i]!='\0')
    {
        if(str[i]=='a' ||str[i]=='e' ||str[i]=='i' ||str[i]=='o' ||str[i]=='u')
        {
            vowels++;
        }
        else if(str[i]==32)
        {
            space++;
        }
        else
        {
            consonant++;
        }
        i++;
    }
    printf("vowels : %d\nconsonant : %d",vowels,consonant);
    return 0;
}

Finding the frequency of elements in an array

#include <stdio.h>
int main()
{
    int n;
    int ijcount=0unique = 0;;
    scanf("%d",&n);
    int array[n];
    int newarray[n];
    for(i=0i<ni++)
    {
        scanf("%d",&array[i]);
    }
    for(i=0i<ni++)
    {
        count = 0;
        for(j=0;j<=i;j++)
        {
            if(array[i]==array[j])
            {
                count++;
            }
        }
        if(count==1)
        {
            newarray[unique] = array[i];
            unique++;
        }
    }
    for(i=0i<uniquei++)
    {
        count = 0;
        for(j=0j<nj++)
        {
            if(newarray[i]==array[j])
            {
               count++;
            }
        }
        printf("%d element is present %d times\n",array[i],count);
    }
    return 0;
}