+ 1
Why this code giving different answer when i = 1 . Please give me logical reason . And how to that we have to put i=0 or i=1 ?
2 Answers
+ 1
With the same inputs,
đfor(i=1;i<=terms-2;i++) {
Gives the same results in your code as
đfor(i=0;i<=terms-3;i++) {
But if you don't change terms-3 then you get 1 less result (1 less loop).
The answer to should we start at i=0 or at i=1 is: depends on your logic.
Many times you will want to start at i=0, eg to access arrays, or to not multiply a variable on the first loop. Most of the time my for loops start at i=0.