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 of (1) 1 and (2) 0 ?
plz answer
Answers
Answered by
42
If n = 1
1 > 0 Condition True 1 is greater than 0
x = 1 + 1
x = 2
y = 1 + 1
y = 2
If n = 0
0 > 0 Condition False
Comes out of the loop
No Output
Answered by
4
Answer:
When n = 1 than the value of x = 2 and y = 2
When n = 0 ,value of x and y remain same .
Explanation:
Given ,
if(n > 0)
{
x = x + 1 ;
y = y +1 ;
}
If the value of n assumes to be 1 then ,
1 > 0 ,the condition is true .
So , its code is executed adding 1 to both x and y.
int x= 1 ,y = 1;
if(1 > 0 )
{
x = 1 + 1
x= 2;
y = 1 +1
y = 2;
}
Output , (1) n = 1
x = 2 and y = 2 .
If the value of n assumes to be 0 then , condition is not satisfy .
Hence , When n = 1 then the condition is true and the value of x is 2 and y is also 2 . When n = 0, condition is false so x and y retain their original values.
#SPJ3
Similar questions