@tesu:
The algorithm is correct. Its just that the first tw0 terms of the series must be printed separately. fibo(18) is 2584 iff fibo(0) = 0. So what you are printing as your first term should be the 2nd term (ie fibo(2) if we take the first term as fibo(0)).

P.S: @xaop
once you get the logic correct spend some time on coming up with meaningful variable names. Also use proper indentation. As of now, a small advice, never use void main(). Its plain wrong (and disrespect to the creators of C).

@tesu:
The algorithm is correct. Its just that the first tw0 terms of the series must be printed separately. fibo(18) is 2584 iff fibo(0) = 0. So what you are printing as your first term should be the 2nd term (ie fibo(2) if we take the first term as fibo(0)).

P.S: @xaop
once you get the logic correct spend some time on coming up with meaningful variable names. Also use proper indentation. As of now, a small advice, never use void main(). Its plain wrong (and disrespect to the creators of C).

Sorry, I don't agree, NPC.

His algorithm does not produce FIB(18). So it must be considered to be incorrect, even if we don't regard his mistake in if-statement.

Here is a somewhat more compact iterative Fibonacci:

Nope, i think you didn't go through my post completely. I said his algo is correct provided you print the first two ie fibo(0) and fibo(1) separately. Also it seems you have introduced an error (a typo, maybe). Look at line no. 6 and 9 of the code which you modified previously. the OP had n=f+s once inside but you made it twice.

Well, your compact code is definitely right but is somewhat hard to read and understand.

I was talking of something like this::

#include <stdio.h>
int main(){
int f=0,s=1,n;
n=f+s;
printf("%2d %5d\n", 0, f); //fibo(0), separately printed
printf("%2d %5d\n", 1, s); //fibo(1), separately printed
for (int i=2; i <=18; i++){
printf("%2d %5d\n", i ,n);
f=s;
s=n;
n=f+s;
}
/*
now result is:
0 0
1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55
11 89
12 144
13 233
14 377
15 610
16 987
17 1597
18 2584
though the OP wanted upto 18 terms and that should have printed upto fibo(17) but i kept fibo(18) coz that seems to be the centre of all confusion :)
*/
}