TCS NQT coding questions 2021 with answers(C/C++/Java)

Spread the love

tcs nqt coding questions helps you to perform well in their appearing exams, be prepare yourself

TCS NQT coding questions 2021:-

QUESTIONS 1:

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 an 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 a point in time. Update the JAR after each purchase and display JAR at the Counter.

The output should give a number of Candies sold and an updated number of Candies in a 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

ANSWER:-

#include<stdio.h>
int main()
{
int n=10, k=5;
int num;
scanf(“%d”,&num);
if(num>=1 && num<=5)
{
printf(“NUMBER OF CANDIES SOLD : %dn”,num);
printf(“NUMBER OF CANDIES LEFT : %d”,n-num);
}
else
{
printf(“INVALID INPUTn”);
printf(“NUMBER OF CANDIES LEFT : %d”,n);
}
return 0;
}

#include <iostream.h>
using namespace std;
int main()
{
int n=10, k=5;
int num;
cin>>num;
if(num>=1 && num<=5)
{
cout<< “NUMBER OF CANDIES SOLD : “<<num<<“n”;
cout<<“NUMBER OF CANDIES LEFT : “<<n-num;
}
else
{
cout<<“INVALID INPUTn”;
cout<<“NUMBER OF CANDIES LEFT : “<<n;
}
return 0

import java.util.Scanner;
class Main{
public static void main(String[] args) {
int n = 10, k = 5;
int num;
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
if(num >= 1 && num <= 5) {
System.out.println(“NUMBER OF CANDIES SOLD : ” + num);
System.out.print(“NUMBER OF CANDIES LEFT : ” + (n – num));
} else {
System.out.println(“INVALID INPUT”);
System.out.print(“NUMBER OF CANDIES LEFT : ” + n);
}
}
}

tcs nqt coding questions problem no2:

QUESTIONS 2:

The selection of MPCS exams includes a fitness test which is conducted on the ground. There will be a batch of 3 trainees, appearing for running test in track for 3 rounds. You need to record their oxygen level after every round. After the trainee is finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select one with the highest oxygen level as the fittest trainee. If more than one trainee attains the same highest average level, they all need to be selected.

Display the fittest trainee (or trainees) and the highest average oxygen level.

Note:

  • The oxygen value entered should not be accepted if it is not in the range between 1 and 100.
  • If the calculated maximum average oxygen value of trainees is below 70 then declare the trainees as unfit with a meaningful message as “All trainees are unfit.
  • Average Oxygen Values should be rounded.

Example 1:

  • INPUT VALUES

95

92

95

92

90

92

90

92

90

  • OUTPUT VALUES
    • Trainee Number : 1
    • Trainee Number : 3

Note:

Input should be 9 integer values representing oxygen levels entered in order as

Round 1

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen values of trainee 3

Output must be in the given format as in the above example. For any wrong input, the final output should display “INVALID INPUT”

 

ANSWER:-

#include <stdio.h>
int main()
{
int trainee[3][3];
int average[3] = {0};
int i, j, max=0;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf(“%d”,&trainee[i][j]);
if(trainee[i][j]<1 || trainee[i][j]>100)
{
trainee[i][j] = 0;
}
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(i=0; i<3; i++) { if(average[i]>max)
{
max = average[i];
}
}
for(i=0; i<3; i++)
{
if(average[i]==max)
{
printf(“Trainee Number : %dn”,i+1);
}
if(average[i]<70)
{
printf(“Trainee is Unfit”);
}
}
return 0;
}

#include<iostream.h>
using namespace std;
int main()
{
int trainee[3][3];
int average[3] = {0};
int i, j, max=0;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++) { cin>>trainee[i][j];
if(trainee[i][j]<1 || trainee[i][j]>100)
{
trainee[i][j] = 0;
}
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(i=0; i<3; i++) { if(average[i]>max)
{
max = average[i];
}
}
for(i=0; i<3; i++)
{
if(average[i]==max)
{
cout<<“Trainee Number : “<<i+1<<“n”;
}
if(average[i]<70)
{
cout<<“Trainee is Unfit”;
}
}
return 0;
}

import java.util.Scanner;
class Main {
public static void main(String[] args) {
int[][] trainee = new int[3][3];
int[] average = new int[3];
int max = 0;
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
trainee[i][j] = sc.nextInt();
if(trainee[i][j] < 1 || trainee[i][j] > 100) {
trainee[i][j] = 0;
}
}
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(int i = 0; i < 3; i++) {
if(average[i] > max) {
max = average[i];
}
}
for(int i = 0; i < 3; i++) {
if(average[i] == max) {
System.out.println(“Trainee Number : ” + (i + 1));
}
if(average[i] <70) {
System.out.print(“Trainee is Unfit”);
}
}
}

}

We all wanted to join in TCS, but no one has the knowledge who is willing to join in TCS. so here we come with TCS NQT coding questions.

277 thoughts on “TCS NQT coding questions 2021 with answers(C/C++/Java)”

  1. Good day I am so thrilled I found your blog page, I really
    found you by error, while I was searching on Aol for something else, Anyhow
    I am here now and would just like to say thanks a lot for a tremendous post and a all round exciting blog (I also love the theme/design), I don’t
    have time to read it all at the minute but I have
    saved it and also added your RSS feeds, so when I have time I will be back to read much more, Please do keep up the excellent job.

    Reply
  2. Hmm it appears like your site ate my first comment (it was
    super long) so I guess I’ll just sum it up what I wrote and say,
    I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to the whole thing.
    Do you have any suggestions for rookie blog writers?
    I’d genuinely appreciate it.

    Reply
  3. I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from. thanks

    Reply

Leave a Comment