# Thread: Fibonacci numbers in C

1. <<split from here>>

I have a question about the following code:

Code:
```int x = 0, y = 1, z;
int i;

for ( i = 0; i < 10; i++ ) {
printf ( "F(&#37;d): %d\n", i, x );
z = x + y;
y = x;
x = z;
}```
I switched the values for x and y so the sequence would display 0 as the first.

I understand everything except

Code:
```z = x + y;
y = x;
x = z;```
So when it runs through the first time, z becomes 0+1=1. but what I don't understand is how y=x and x=z..

It seems to me that x equals 0, making y =0, then making z, which is 1 equal x. So you have 0 and 1 again.

Can anyone explain to me the logic of this sequence?

2. Y gets copied to X, so the smallest number is lost. Z gets copied to Y so the last number result is stored. IE:
Code:
```x    y     z
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13```
Oh yeah changed the variable names around in my explanation, but I hope at least it helps explain what your output should look like.

3. Yeah, that makes sense. Thanks mike