# TCS Recursion and Iteration Questions Quiz-1

Question 1

Time: 00:00:00
function main() { integer a=5,b=7 switch(a) { case 5 :print "I am 5" break case b:print "I am not 5" break default:print "I am different" } }

I am 5

I am 5

I am not 5

I am not 5

I am different

I am different

Error

Error

Once you attempt the question then PrepInsta explanation will be displayed.

In function ‘main’: main.c:19:9: error: case label does not reduce to an integer constant case b:

we can not use integer constant (b variable here) with switch

There is no data type like function...and we can not use int data type as integer...so this will get an error

Case label does not reduce to an integer constant

Start

Question 2

Time: 00:00:00
Ashima wants to print a pattern which includes checking and changing a variables value iteratively She decides to use a loop/condition Which of the following options should she use such that the body of the loop/condition is executed atleast once whether the variable satisfies the entering condition or not?

For loop

For loop

While Loop

While Loop

Do while loop

Do while loop

Switch case

Switch case

Once you attempt the question then PrepInsta explanation will be displayed.

Start

Question 3

Time: 00:00:00
The construct “if (condition) then A else B” is for which of the following purposes?

Iteration

Iteration

Decision Making

Decision Making

Recursion

Recursion

Object Oriented Programming

Object Oriented Programming

Once you attempt the question then PrepInsta explanation will be displayed.

Start

Question 4

Time: 00:00:00
Ravi and Rupali are asked to write a program to sum the rows of 2X2 matrices stored in the array A.
Ravi writes the following code (Code A):
for n = 0 to 1
sumRow1[n] = A[n][1] + A[n][2]
end
Rupali writes the following code (Code B):
sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2]
Comment upon these codes (Assume no loop­ unrolling done by compiler):

Code A will execute faster than Code B

Code A will execute faster than Code B

Code B will execute faster than Code A

Code B will execute faster than Code A

Code A is logically incorrect.

Code A is logically incorrect.

Code B is logically incorrect.

Code B is logically incorrect.

Once you attempt the question then PrepInsta explanation will be displayed.

Start

Question 5

Time: 00:00:00
Integer a =40, b =35, c=20, d =10
Comment about the output of the following two statements •
```Print a*b/c-d
Print a*b/(c-d)```

Comment about the output of the following two statements

Differ by 80

Differ by 80

Same

Same

Differ by 50

Differ by 50

Differ by 160

Differ by 160

Once you attempt the question then PrepInsta explanation will be displayed.

Option 1is correct ...differ by 80 60 140

Differ by 80

a*b/c-d=60 {b/c=>35/20=1.75,a*b/c=>40*1.75=70,70-d=>60} a*b/(c-d)=140 {(c-d)=>10,b/(c-d)=3.5,a*3.5=>140} Difference=140-60=>80

Start

Question 6

Time: 00:00:00
What is the output of the following pseudo code?

Int a =456,b,c,d=10;
b=a/d;
c=a-b;
print c;

411

411

410

410

456

456

none of these

none of these

Once you attempt the question then PrepInsta explanation will be displayed.

Incorrect Options

incorrect options

Prints c value as 411

Start

Question 7

Time: 00:00:00
Function main()
{
Integer i=0.7
Static float m=0.7
If(m equals i)
Print(“We are equal”)
Else If(m>i)
Print(“I am greater”)
Else
Print(“I am lesser”)

We are equal

We are equal

I am greater

I am greater

I am lesser

I am lesser

This code will generate an error

This code will generate an error

Once you attempt the question then PrepInsta explanation will be displayed.

The answer will be \"I am greater\", when defining i as int, it automatically converts it into and integer of a lesser value, hence i=0. Try the same code in any compiler

Ya right answer is i am greater , i tried and code complie the answer is B

Start

Question 8

Time: 00:00:00
Recursion is a method in which the solution of a problem depends on ____________

Larger instances of different problems

Larger instances of different problems

Larger instances of the same problem

Larger instances of the same problem

Smaller instances of the same problem

Smaller instances of the same problem

Smaller instances of different problems

Smaller instances of different problems

Once you attempt the question then PrepInsta explanation will be displayed.

Start

Question 9

Time: 00:00:00
Which of the following problems can be solved using recursion?

Factorial of a number

Factorial of a number

Nth fibonacci number

Nth fibonacci number

Length of a string

Length of a string

All of the mentioned

All of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Start

Question 10

Time: 00:00:00
Recursion is similar to which of the following?

Switch Case

Switch Case

Loop

Loop

If-else

If-else

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Start

["0","40","60","80","100"]
["Need more practice! \r\n \r\n","Keep trying! \r\n \r\n","Not bad! \r\n \r\n","Good work! \r\n \r\n","Perfect! \r\n \r\n"]

Buy TCS Prog. Logic (C MCQ) Paid Materials

Join TCS Online Classes

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Completed

0/10

Accuracy

0%

##### Get Prepinsta Prime

Get all 200+ courses offered by Prepinsta

### Never Miss an OffCampus Update

Get OffCampus Updates on Social Media from PrepInsta

Follow us on our Media Handles, we post out OffCampus drives on our Instagram, Telegram, Discord, Whatsdapp etc.

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

## Get PrepInsta Prime Subscription

Get access to all the courses that PrepInsta offers, check the out below -

### Companies

TCS, Cognizant, Delloite, Infosys, Wipro, CoCubes, KPMG, Amazone, ZS Associates, Accenture, Congnizant & other 50+ companies

### Programming

Data Structures, Top 500 Codes, C, C++, Java Python & other 10+ subjects

### Skills

Full Stack Web Development, Data Science, Machine Learning, AWS Cloud, & other 10+ skills and 20+ projects