TCS Programming Logic Questions
Ques101. Consider the statement while (a < 10.0) { a = a a }
Assuming a is positive, for what value of a will this code statement result in an infinite loop?
Op 1: a < 1.0
Op 2: a < sqrt(10)
Op 3: a > sqrt(10)
Op 4: a = 0
Op 5:
Correct Op : 1
Ques102. int area(double radius)
{
return PI radius radius;
}
Which of the following is always true about the function area?
Op 1: It returns the area of a circle within the limits of double precision.
Op 2: It returns the area of a circle within the limits of the constant PI.
Op 3: It returns the area of a circle within the limits of precision of double, or the constant PI, whichever is lower.
Op 4: None of the above.
Op 5:
Correct Op : 4
Ques103. What does this function compute for positive n? function f(int n)
{
if (n equals 1)
{ return 1 } else
{ return f(n-1)/f(n-1) + n }
}
Op 1: 1 + n
Op 2: 1 + 2 + 3 + ... + n
Op 3: 1 + n, if n > 1, 1 otherwise
Op 4: None of the above
Op 5:
Correct Op : 3
Ques104. Which of these is not a data type?
Op 1: integer
Op 2: character
Op 3: boolean
Op 4: array
Op 5:
Correct Op : 4
Ques105. The construct "if (condition) then A else B" is for which of the following purposes?
Op 1: Decision-Making
Op 2: Iteration
Op 3: Recursion
Op 4: Object Oriented Programming
Op 5:
Correct Op : 1
Ques106. In a sequential programming language, code statements are executed in which order?
Op 1: All are executed simultaneously
Op 2: From top to bottom
Op 3: From bottom to top Op 4: None of these
Op 5:
Correct Op : 2
Ques107. A for-loop is used for which of the following purposes?
Op 1: Decision-Making
Op 2: Iteration
Op 3: Recursion
Op 4: None of these
Op 5:
Correct Op : 2
Ques108. There are two loops which are nested. This implies which one of the following?
Op 1: Two loop, one after the other
Op 2: Two loops, one inside the others
Op 3: One loop with two different iteration counts
Op 4: Two loops with the same iteration count
Op 5:
Correct Op : 2
Ques109. How will 47 be stored as an unsigned 8-bit binary number?
Op 1: 10111101
Op 2: 00101111
Op 3: 10111000
Op 4: 00101101
Op 5:
Correct Op : 2
Ques110. An integer X is saved as an unsigned 8-bit number, 00001011.What is X?
Op 1: 22
Op 2: 11
Op 3: 10
Op 4: None of these
Op 5:
Correct Op : 2
Ques111. A variable cannot be used…
Op 1: Before it is declared
Op 2: After it is declared
Op 3: In the function it is declared in
Op 4: Can always be used
Op 5:
Correct Op : 1
Ques112. What is implied by the argument of a function?
Op 1: The variables passed to it when it is called
Op 2: The value it returns on execution
Op 3: The execution code inside it
Op 4: Its return type Op 5:
Correct Op : 1
Ques113. Which of the following is true about comments?
Op 1: They are executed only once.
Op 2: They are not executed
Op 3: A good program does not contain them
Op 4: They increase program execution time.
Correct Op : 2
Ques114. Neelam wants to share her code with a colleague, who may modify it. Thus she wants to include the date of the program creation, the author and other information with the program. What component should she use?
Op 1: Header files
Op 2: Iteration
Op 3: Comments
Op 4: Preprocessor directive
Correct Op : 3
Ques115. Shashi writes a program in C++ and passes it on to Pankaj. Pankaj does some indentation in some statements of the code. What will this lead to?
Op 1: Faster Execution
Op 2: Lower memory requirement
Op 3: Correction of errors
Op 4: Better readability
Op 5:
Correct Op : 4
Ques116. Zenab and Shashi independently write a program to find the the mass of one mole of water, which includes mass of hydrogen and oxygen. Zenab defines the variables:
integer hydrogen, oxygen, water // Code A while Shashi defines the three quantities as:
integer a, b, c // Code B
Which is a better programming practice and why?
Op 1: Code B is better because variable names are shorter
Op 2: Code A is better because the variable names are understandable and nonconfusing
Op 3: Code A will run correctly, while Code B will give an error.
Op 4: Code B will run correctly, while Code A will give an error.
Correct Op : 2
Ques117. For solving a problem, which of these is the first step in developing a working program for it?
Op 1: Writing the program in the programming language
Op 2: Writing a step-by-step algorithm to solve the problem.
Op 3: Compiling the libraries required.
Op 4: Code debugging
Correct Op : 2
Ques118. A robust program has which one of the following features?
Op 1: It runs correctly on some inputs
Op 2: It is robust to hardware damage
Op 3: It can handle incorrect input data or data types.
Op 4: None of these
Correct Op : 3
Ques119. Tarun wants to write a code to divide two numbers. He wants to warn the user and terminate the program if he or she enters 0 as the divisor. Which programming construct can he use to do this?
Op 1: Iteration
Op 2: Decision-making
Op 3: Recursion
Op 4: None of these
Correct Op : 2
Ques120. To solve a problem, it is broken in to a sequence of smaller sub-problems, till a stage that the sub-problem can be easily solved. What is this design approach called?
Op 1: Top-down Approach Op 2: Bottom-Up Approach
Op 3: Procedural Programming
Op 4: None of these
Op 5:
Correct Op : 1
Ques121. The time complexity of linear search algorithm over an array of n elements is
Op 1: O (log2 n)
Op 2: O (n)
Op 3: O (n log2 n )
Op 4: O (n2)
Correct Op : 2
Ques122. Rajesh implements queue as a singly-linked linked list. The queue has n elements. The time complexity to ADD a new element to the queue:
Op 1: O (1)
Op 2: O (log2 n)
Op 3: O (n)
Op 4: O (n log2 n )
Correct Op : 1
Ques123. The time required to insert an element in a stack with linked list implementation is
Op 1: O (1)
Op 2: O (log2 n)
Op 3: O (n)
Op 4: O (n log2 n )
Correct Op : 1
Comments
Post a Comment