Tell us what’s happening:
Describe your issue in detail here.
So I want to print first n fibonacci numbers when i run the function fib(n). But in the output, it is returning the nth number twice even though i have provided the condition of i < num in the code below. Example if i run fib(5), the output comes as “1 1 2 3 5 5”.
Oh got you. So basically the output of arr[i] = arr[i-1] + arr[i-2]; automatically gets inserted in the arr. I was of the view that once the result comes, it has to be pushed in the chosen array.