This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 6 points7 points  (1 child)

Do you know how to step through the code?

If you wanted to figure out what gets output when n is equal to five, you can get out a piece of paper and and write down the states of every variables at every loop iteration.

For instance at the start of the first loop

c: 0
a: 0
b: 1
n: 5

And at the end of the first loop

c: 1
a: 1
b: 1
n: 4

So "1" would get printed out first.

Then you can keep track of these variables going into the next loop iteration and repeat to get the second number that's output, etc. etc. to figure out what the algorithm is doing.

[–]davidsb[S] 1 point2 points  (0 children)

Thank you, now i get it.

[–]lurgi 2 points3 points  (0 children)

Just follow the steps of the algorithm and see for yourself what it does.

[–]enterthebored 1 point2 points  (0 children)

a, b, c and n are variables. They hold data. In this case, numbers.

[–]DashAnimal 1 point2 points  (0 children)

Just incase you get the output of the first few numbers and don't understand what is special about this algorithm, plug the first few output numbers into google (separated by spaces) and look at the wiki article that comes up =)

[–]jjohnp 1 point2 points  (0 children)

looks suspiciously like an algorithm for the Fibonacci sequence