Nth Fibonacci Number

At 3:36 Prateek bhaiya says that we need to use the for loop until (n-2)th number but I think that is not the case.

hello @yajurkhurana
in the video , bhaiya is counting from 0 (i.e number 0 is considered at 0th place)thats why he is using n-1 in the loop.

But later bhaiya used n-1 instead of n-2 and was still counting from 0 (i.e number 0 is considered at 0th place).
Please explain.

ok lets dry run.

yeah the later one is correct.

a=0
b=1
then we iterate n-1 times ( n is 6 so n-1 will be 5)
1st iteration -> c will be 1
2nd iteration -> c will be 2
3rd iteration -> c will be 3
4th iteration -> c will be 5
5th iteration -> c will be 8

so thats how 6th fib is coming 8.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.