In: Computer Science
x, y, z, w, u and t are integer variables, what will their value be after the execution of the statements below. Give the final value of each variable
x = 7;
y = x + 1;
z = x % (y – 2) + 4;
y = (y + z ) % (x + 4) ;
w = (x * y) / (z – 3);
x = x + x;
u = w - 3;
t = z + (x + y + 2) % w;
1) x=7
2) y= x+1
y=7+1
y=8
3) z = x % (y – 2) + 4;
z = 7%(8-2)+4; (here () is higher precedence so first calculate the values whith in braces.)
z = 7%6+4; (Here % is higher precedence so first first we do modulo operation)
z= 1+4
z=5
4) y = (y + z ) % (x + 4) ;
y = (8 + 5) % (7 +4); (Here () is higher precedence so first calculate the values whith in braces. precedence is left to right)
y = 13%11
y = 2 (Now the value of y is updated to 2 from 8)
5) w = (x * y) / (z – 3);
w = ( 7*2)/(5-3);
w = 14 / 2
w =7
6) x = x + x;
x= 7 + 7
x = 14 (Now the value of x is updated to 14 from 7)
7) u = w - 3
u = 7-3
u = 4
8) t = z + (x + y + 2) % w
t = 5 + ( 14 + 2+ 2) % 7 (Here () have higher precedence than % and +)
t = 5 +18 %7 (Here % have higher precedence than +,so first we do % operation)
t = 5+4
t =9
The value of x is : 14
The value of y is : 2
The value of w is : 7
The value of z is : 5
The values of u is : 4
The value of t is : 9
PLEASE UPVOTE