Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 8

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
Answer: Option A

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

Answer: Option B
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.

Answer: Option D

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.

Answer: #include”stdio.h”

#include”math.h”

int main()

//Type your code here

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

Answer: Option D

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

Answer: Option B

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.

Answer: #include<stdio.h>

#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

Answer: Option A

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

Answer: Option D

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;

Answer: Option B

Explanation:

space, comma and $ cannot be used in a variable name.

above were some most asked question in TCS Recruitment exams

You might also like