GATE 1993
January 31, 2024
GATE 1996
February 1, 2024
GATE 1993
January 31, 2024
GATE 1996
February 1, 2024

GATE 2003

Question 1

Consider the following C function.

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
Xy
B
ex
C
ln(1+x)
D
Xx
Question 1 Explanation: 
P = P * (x/i)
S = S+P
Iteration 1:
P=1; i=1; S=1
P=x
S = 1+x
Iteration 2:
P=x; S = 1+x; i=2
P = x * x/2 = x2/2
Iteration 3:
P = x2/2; S = 1+x+x2/2; i=3
P = (x2/2)(x/3) = x3/6
S = 1 + x + x2/2 + x3/6
Continue upto n
Then f( ) returns
:
S = 1 + x/1 + x2/2⋅1 + x3/3⋅2 + …
= 1 + x/1! + x2/2! + x3/3! + … + xn/n!
= ex
Correct Answer: B
Question 1 Explanation: 
P = P * (x/i)
S = S+P
Iteration 1:
P=1; i=1; S=1
P=x
S = 1+x
Iteration 2:
P=x; S = 1+x; i=2
P = x * x/2 = x2/2
Iteration 3:
P = x2/2; S = 1+x+x2/2; i=3
P = (x2/2)(x/3) = x3/6
S = 1 + x + x2/2 + x3/6
Continue upto n
Then f( ) returns
:
S = 1 + x/1 + x2/2⋅1 + x3/3⋅2 + …
= 1 + x/1! + x2/2! + x3/3! + … + xn/n!
= ex
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!