Iterative Fibonacci code in Java?

In fibonacci sequence each item is the sum of the previous two. So, you wrote a recursive algorithm. So, Now you already know fibonacci(1)==1 and fibonacci(0) == 0. So, you can subsequently calculate the other values. Now, And from fibonacci sequence 0,1,1,2,3,5,8,13,21…. we can see that for 5th element the fibonacci sequence returns 5. like … Read more

How to iterate over a string in C?

You want: sizeof gives you the size of the pointer, not the string. However, it would have worked if you had declared the pointer as an array: but if you pass the array to function, that too will decay to a pointer. For strings it’s best to always use strlen. And note what others have … Read more

How to loop backwards in python?

range() and xrange() take a third parameter that specifies a step. So you can do the following. Which gives But for iteration, you should really be using xrange instead. So, Note for Python 3 users: There are no separate range and xrange functions in Python 3, there is just range, which follows the design of Python 2’s xrange.