2,026 views

3 Answers

Best answer
15 votes
15 votes
while(m++ < n)

here , we have used post-increment operator for variable $m$. So, first we will check whether $m<n$ is true or not then we will increase the value of '$m$' as $m=m+1$.

So, for $n=2$ , first we will go in the loop.

So, $t = 1*(\frac{-x}{1})$ and $y = 0 + (1*(\frac{-x}{1})) = \frac{-x}{1}$

Now, we will check the condition as :- $(1<2)$ . Since, it is true so we will go in the loop again as well as we will increment the value of $m$. So, now, $m=2$

Now again, in the body of the loop,

$t = (1*(\frac{-x}{1}))* (\frac{-x}{2})$ and $y = (1*(\frac{-x}{1})) + (1*(\frac{-x}{1})*(\frac{-x}{2})) = (-1)^{1}*\frac{x^{1}}{1} + (-1)^{2}*\frac{x^{2}}{1*2}$

Like this when we do then at certain point of time , we will check $((n-1) < n)$  or not for the value of $m=n-1$ . since it is true  . So, again we will go in the loop and increment in value of m.So, now , $m=n$

So, Now , $y = 0 + \frac{(-1)^{1}*(x^{1})}{1} + \frac{(-1)^{2}*x^{2}}{1*2} + \frac{(-1)^{3}*x^{3}}{1*2*3}+....+\frac{(-1)^{n}*x^{n}}{1*2*3*...*n}$ = $\sum_{i=1}^{n} \frac{ (-1)^{i}*x^{i}}{i!}$

Now again, we will check the condition. Since $(n<n)$ is false. So, we will not go in loop again and print the value of $y$ which is $\sum_{i=1}^{n} \frac{ (-1)^{i}*x^{i}}{i!}$
selected by
3 votes
3 votes
The returned value is

$\sum_{i=1}^n (-1)^i \frac{x^i}{i!}$
3 votes
3 votes
$t=1, y=0, m=1$

$t=t*\left ( -\left ( \frac{x}{m} \right ) \right )=1\times \left ( -\frac{x}{1} \right )$

$y=y+t=0-x$

for $m=2$

$t=t*\left ( -\left ( \frac{x}{m} \right ) \right )=\left ( -x \right )\times \left ( -\left ( \frac{x}{2} \right ) \right )=\frac{x^{2}}{2}$

$y=y+t=0-x+\left (\frac{ x^{2}}{2} \right )$

That is $e^{-x}-1$

Related questions

7 votes
7 votes
1 answer
2
makhdoom ghaya asked Nov 25, 2016
2,381 views
Consider a hash table with chaining scheme for overflow handling:What is the worst-case timing complexity of inserting $n$ elements into such a table?For what type of ins...