GATE CS 2024 Set 1 — Question 48
MSQ+2 / -0MediumControl FlowC ProgrammingProgramming & Data Structures
Programming & Data Structures → C Programming → Control Flow
Last updated
Question
Consider the following C function definition.```c
int f(int x, int y) {
for (int i=0; i
int f(int x, int y) {
for (int i=0; i
A.
If the inputs are , then the return value is greater than
B.
If the inputs are , then the return value is greater than
C.
If the inputs are , then the return value is less than
D.
If the inputs are , then the return value is greater than
Correct answer
(B) If the inputs are x=20, y=20, then the return value is greater than 2²⁰; (D) If the inputs are x=10, y=20, then the return value is greater than 2²⁰
Solution
The function updates the variable in a loop that iterates times. Let denote the value of after iterations, with being the initial input . The update rule in each iteration is:This is a linear recurrence relation. We can find the general term by observing the first few iterations:
- (A) and (C): For , the return value is .
- is much smaller than , so (A) is false.
- is greater than , so (C) is false.
- (B): For , the return value is . Since , (B) is true.
- (D): For , the return value is . Since , (D) is true.
More questions on C Programming
2024 Set 2 Q13Consider the following C program. Assume parameters to a function are evaluated from right to left.…2024 Set 2 Q17Let be the adjacency matrix of a simple undirected graph . Suppose is its own inverse.…2024 Set 1 Q17Given an integer array of size , we want to check if the array is sorted (in either ascending or…2024 Set 1 Q18Consider the following C program: [code] Which one of the following statements is CORRECT?2024 Set 1 Q19Consider the following C program: [code] Assume that the input to the program from the command line…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free