Computer Science, asked by arkafrontech, 5 months ago

e)Predict the output of the given snippet , when executed:
int x=1,y=1;
if(n>0)
{
x=x+1;
y=y+1;
}
What will be the value of x and y,if n assumes a value i) 1 ii) 0?

Answers

Answered by Imblank
12

Answer:

i) x = 2, y = 2

ii) x = 1, y = 1

Read my bio once

Answered by asthakumari06
9

Questions

Predict the output of the given snippet, when executed

Question 1

int x = 1,y = 1;

if(n>0)

{

x=x+1;

y=y+1;

}

What will be the value of x and y, if n assumes a value (i) 1 (ii) 0?

Answer.

Output

When n is 1:

x is 2 and y is 2

When n is 0:

x is 1 and y is 1

Explanation

When n is 1, if (n>0) is true. So the statements x=x+1; and y=y+1; are executed making the values of x and y as 2.

When n is 0, if (n>0) is false. Statements x=x+1; and y=y+1; are not executed so values of x and y remain 1.

Similar questions