edited by
1,335 views
16 votes
16 votes

Consider the following functions $f$ and $g$.
 

f(){
x = x-50; 
y = y+50;
}
g( ) {
a = a+x;   
a = a+y;
}

Suppose we start with initial values of $100$ for $x, 200$ for $y$, and $0$ for $a$, and then execute $f$ and $g$ in parallel - that is, at each step we either execute one statement from $f$ or one statement from $g$. Which of the following is not a possible final value of $a$?

  1. $300$
  2. $250$
  3. $350$
  4. $200$
edited by

2 Answers

Best answer
11 votes
11 votes

Answer is (D) $200$

If we execute first $f()$ and then $g()$ then we get $300$

If we execute $1^{st}$ line of $g()$ , then $f()$ all the lines and then last line of $g()$ ,will get $350$

If we execute $1^{st}$ line of $f()$, then $1^{st}$ line of $g()$, then 2nd line of $g()$ and then $2^{nd}$ line of $f()$, we get $250$

edited by
0 votes
0 votes
as we are adding y to a's value and minimum value of 'a' at point a=a+x; can be 50....so the final value of 'a'  (at a=a+y;) has to be greater than 200 (max. value of 'a' can be 350)
Answer:

Related questions

14 votes
14 votes
2 answers
1
8 votes
8 votes
5 answers
3
go_editor asked May 22, 2016
1,999 views
A man has three cats. At least one is male. What is the probability that all three are male?$\frac{1}{2}$$\frac{1}{7}$$\frac{1}{8}$$\frac{3}{8}$
7 votes
7 votes
2 answers
4