Open In App

GATE | GATE-CS-2003 | Question 1

Like Article
Like
Save
Share
Report

Consider the following C function. 

C




float f(float x, int y)
{
  float p, s; int i;
  for (s=1, p=1, i=1; i < y; i ++)
  {
    p*= x/i;
    s+=p;
  }
  return s;


For large values of y, the return value of the function f best approximates

(A)

x^y

(B)

e^x

(C)

ln(1 + x)

(D)

x^x



Answer: (B)

Explanation:

The provided function computes the sum of a Taylor series approximation for (e^x) up to the (y)th term. This function is essentially approximating the exponential function (e^x).

For large values of (y), the function will approximate (e^x) more accurately because it includes more terms of the Taylor series expansion, resulting in a better approximation.

Therefore, for large values of (y), the return value of the function (f(x, y)) will best approximate (e^x).

Now,expanding ex=1+x+x2/2+x3/3+x4/4………

So final answer should be ex


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads