What value get assigned to variable y after execution of the following two statements: int x=5, y=13; y= (y/x*20+1)/3;
Question
What value get assigned to variable y after execution of the following two statements:
int x = 5, y = 13;
y = (y / x * 20 + 1) / 3;
Solution
The given statements are in a programming language, likely C, C++, or Java. Here's how the execution of the statements would go:
-
The first statement
int x=5, y=13;
declares two integer variablesx
andy
, and assigns them the values5
and13
respectively. -
The second statement
y= (y/x*20+1)/3;
performs several operations:- First,
y/x
is calculated. Sincey
andx
are integers, this will perform integer division, which discards the remainder and only keeps the quotient. So13/5
equals2
. - Then,
2*20
is calculated, which equals40
. 40+1
is then calculated, which equals41
.- Finally,
41/3
is calculated. Again, since these are integers, the division will discard the remainder. So41/3
equals13
.
- First,
So, after the execution of these two statements, the value assigned to the variable y
would be 13
.
Similar Questions
What will be the value of x after the following code snippet?int x = 5;x *= 2 + 3;Question 5Answera.10b.15c.25d.30
What is the output of the following code snippet? int x = 5; int y = 2; System.out.println(x / y);
x varies directly as y2. Given that for y=3, x=2. The value of x when y=5 will be
What is the output of the following code snippet?int x = 5;int y = 2;int result = x % y;System.out.println(result);Question 2Answera.3b.2c.1d.0
What is the value of Variable A after the execution of fowling code?int a=5;int A=0;for(int i=0;i<=a;i++){A=A+i;}10515-10
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.