First, please use
CODE tags to keep your formatting intact. Here is your code (as you entered it) with tags...
Now, to see what's happening, take a look at the for loop, and consider what happens on the first iteration (when n1 and n2 both start as 1, and i is 2)...
n1 = n2 + i; //n1 = 1 + 2 = 3
i = n2; //i = 1
n2 = n1; //n2 = 3
Hmmm... Is that what you want? Both n1 and n2 to end up equal? Look at the next iteration (after i has been incremented to 2)...
n1 = n2 + i; //n1 = 3 + 2 = 5
i = n2; //i = 3
n2 = n1; //n2 = 5
And then (after i has been incremented to 4)...
n1 = n2 + i; //n1 = 5 + 4 = 9
i = n2; // i = 5
n2 = n1; //n2 = 9
Basically, you're using the variable i as a counter, to count from 2 to n. But within your for loop, you're assigning i a different number. I think you would do better using n1 and n2 to store your sequence values, and leave i alone to count.
Also, when you're done, you probably don't want to return n.
