No need to remember series expansion just use Taylor series for getting expansion of f(x).

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+11 votes

Consider the following $C$ function.

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

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; }

- $x^y$
- $e^x$
- $\text{ln} (1+x)$
- $x^x$

+19 votes

Best answer

A simplified version of the given program can be written as:

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

We can take $p=1,s=1$ initialization outside of for loop because there is no condition checking in for loop involving $p,s$ .

$i$ | $p= p $*$ (x/i)$ | $s= s + p$ |

$1$ | $x$ | $1+x$ |

$2$ | $\frac{x^{2}}{2}$ | $1+x+\frac{x^{2}}{2}$ |

$3$ | $\frac{x^{3}}{6}$ | $1+x+\frac{x^{2}}{2}+\frac{x^{3}}{6}$ |

$4$ | $\frac{x^{4}}{24}$ | $1+x+\frac{x^{2}}{2}+\frac{x^{3}}{6}+\frac{x^{4}}{24}$ |

$n$ | $\frac{x^{n}}{n!}$ | $e^x$ |

$e^x = \displaystyle{\sum_{n=0}^{\infty} \frac{x^n}{n!}} = 1+x+\frac{x^{2}}{2}+\frac{x^{3}}{6} +\frac{x^{4}}{24}+ \ldots+\frac{x^{n}}{n!}$ |

Hence, option **B** is answer.

+23 votes

$$\begin{array}{l}

i = 1 &\rm then& p = x &\&& s = 1 + x\\[1em]

i = 2 &\rm then& p = \frac{x^2}{2} &\&& s = 1+x+\frac{x^2}{2}

\end{array}$$

As $y$ tends to infinity, $s$ tends to $e^x$.

**Hence, the correct answer is option B.**

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 5.9k
- Digital Logic 2.3k
- Programming & DS 4.2k
- Algorithms 3.7k
- Theory of Computation 4.6k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.4k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 15

40,875 questions

47,535 answers

146,075 comments

62,300 users