GATE CSE 2021 Set 1 Q58: Value returned by a Horner-style loop on an all-ones array
- Programming and Data Structures
- 2 marks
- NAT
- No negative marking
Question
Consider the following ANSI C function:
Let Z be an array of 10 elements with Z[] = 1, for all such that . The value returned by SimpleFunction(Z, 10, 2) is ________.
int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)
total = x * total + Y[loopIndex];
return total;
}Try it: numerical answer: type the value
Numerical answer. No negative marking.
Show answer and explanation
Answer: 1023 (official GATE 2021 final answer key)
Concept used: The loop is Horner's rule: it evaluates the polynomial with coefficients Y[0..n−1] at x.
First step: With all coefficients 1 and , the result is .
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2021 Set 1 CS question paper and final answer key, organised by IIT Bombay. Question paper · Answer key
More Programming and Data Structures PYQs
- 2026 Session 1 · Q23Non-leaf indices in a 1-indexed binary heap with n odd
- 2026 Session 1 · Q24Empty slots after linear-probing inserts with h(x) = (x+7) mod 11
- 2026 Session 1 · Q33Maximum height of a full binary tree with 23 nodes
- 2026 Session 1 · Q34Output of a C function with a shadowed block variable
- 2026 Session 1 · Q39Recursive length of a non-empty singly linked list
- 2026 Session 1 · Q40Third insertion that can never yield a complete BST of 1..15