1. ## question

I need some help with this:
Given: int x,y,z What are the values of x,y and z after the following code segments have been executed?

x=2; y=0; z=2;
if(x)
{
if(y)
z=1;
}
else
z=3;

The answer is x=2, y=0, and z=2 I have no clue how to do this. This is my first programming class and I would greatly appreciate any help on this! Thanks so much

2. Well the answer is correct.
What is happening is that if(x) is true so it goes on to the next which is if(y). Here it is false so it is skipping the z=1 command. Since the first IF is correct it is skipping the ELSE. The values have not been changed.

3. I have another for ya:
x=3;
y=0;
z=1;

if(x)
{
if(y)
if(z)
y=4;
else
x=2;
}
else
z=5;

The answers are x=3, y=0, and z=1
I dont really understand how to get those answers. Again thank you so much for all of your help!

4. Maggie,

Your instructor is asking you very good, basic questions to get you familiar with loops and truth tests.

Look at it this way (and keep in mind Thantos's post as you read this):

If (x)
printf("x is TRUE\n");

else
printf("x is FALSE\n");

The above If statement will execute if x evaluates to true. In C, "true" means any non-zero number. So if X is -2, 5, 100, or even 0.1, the If statement will execute. The If statement will not execuate if x is false. In C, "false" means the value zero.

5. Thanks alot for your help! I understand now how to do these things. I really appreciate it!

6. Another thing you may want to do is put spacing and {} in the program. It might make things clearer.

Code:
```int main(void)
{
int x,y,z;

x=3;
y=0;
z=1;

if(x)
{
if(y)
{
if(z) {y=4;}
else {x=2;}
}
}
else
z=5;
}```
I know for me it makes it a little bit more readable and easier to understand.

7. That helped me alot! Its alot easier to read and understand whats happening. Thanks again!