AMCAT coupon code --> AF01 (Upto 150 off)

# TCS Coding Questions | Most Asked Questions in 2019 Recruitment

TCS conducts its recruitment through various exams like TCS ccqt, TCS ninja etc. and for all of them the pattern of coding questions are almost similar. So in this article we will be sharing some coding questions which can help you by giving a boost to your preparation. All these questions can help you if you are planning to give TCS recruitment exams in 2020.

Contents

## TCS Coding Questions

Here are some of the most asked questions in coding section of TCS which will be helpful for TCS recruitment in 2020.

Question 1: The following query belongs to which condition types? SELECT fname FROM person WHERE dept_id= (SELECT dept_id FROM department WHERE names=’s’);

1. Equality condition
2. Inequality condition
3. Range condition
4. All of the mentioned

### Most Employability Test 2019

Question 2: What is the output of this C code?

typedef struct p

{

int x, y;

}k;

int main()

{

struct p p = {1, 2};

k k1 = p;

printf(“%d\n”, k1.x);

}

A. Compile time error

B.1

C. 0

D. Depends on the standard

Question 3: typedef which of the following may create problem in the program?

A. ;

B. printf/scanf

C.Arithmetic operators

D. All of the mentioned.

Question 4: 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”math.h”

int main()

{

int input;

scanf(“%d”, &input);

if(input % 2 == 0)

{

int number = input/2;

int x = number – 1;

int output = pow(3, x);

printf(“%d”, output);

}

else

{

int number = (input+1)/2;

int x = number – 1;

int output = pow(2, x);

printf(“%d”, output);

}

return 0;

}

Question 5:  What is the output of this C code?

int main()

{

int a = 0, i = 0, b;

for (i = 0;i < 5; i++)

{

a++;

continue;

}

}

A. 2

B. 3

C. 4

D. 5

#### TCS Directory

 TCS Recruitment (A to Z) Details TCS Next Steps Registration – Apply Here TCS Ninja Hiring – Register Here TCS ION CCQT – Check Details TCS Ignite 2019 Registration TCS Eligibility Criteria – Read Here

Question 6: What is the output of this C code?

void foo();

int main()

{

void foo();

foo();

return 0;

}

void foo()

{

printf(“2 “);

}

A. Compile time error

B. 2

C. Depends on the compiler

D. Depends on the standard

Question 7: For Example, consider the given series: 1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …

This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and all the even terms are the prime numbers in ascending order. Now write a program to find the Nth term in this series.

#define MAX 1000

void fibonacci(int n)

{

int i, t1 = 0, t2 = 1, nextTerm;

for (i = 1; i<=n; i++)

{

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

}

printf(“%d”, t1);

}

void prime(int n)

{

int i, j, flag, count =0;

for (i=2; i<=MAX; i++)

{

flag = 0;

for (j=2; j<i; j++)

{

if(i%j == 0)

{

flag = 1;

break;

}

}

if (flag == 0)

if(++count == n)

{

printf(“%d”, i);

break;

}

}

}

int main()

{

int n;

scanf(“%d”, &n);

if(n%2 == 1)

fibonacci (n/2 + 1);

else

prime(n/2);

return 0;

}

Question 8: Which of the following cannot be a variable name in C?

A. Volatile

B. True

C. friend

D. export

Question 9: Which of the following is not a valid variable name declaration?

A. float PI = 3.14;

B. double PI = 3.14;

C. int PI = 3.14;

D. #define PI 3.14

Question 10: Which is valid C expression?

A. int my_num = 100,000;

B. int my_num = 100000;

C. int my num = 1000;

D. int \$my_num = 10000;