GATE CS 2021 Set 1 | Question 58

Programming & Data Structures › Arrays & Strings · NAT · 2 marks · Answer: 1023

  1. Question 58Programming & Data Structuresnat2 marks
    Consider the following ANSI C function:
    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;
    }
    Let Z be an array of 10 elements with Z[i]=1, for all such that . The value returned by SimpleFunction(Z, 10, 2) is ______.

    Answer: 1023

    Solution

    This is Horner evaluation of the polynomial with all coefficients 1 at : .

More GATE PYQ on Arrays & Strings

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2021 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →