0

Fibonaci numbers with loop( not recursion)

Can you show me the loop only which show till Nth fibonaci numbers

28th Jan 2018, 7:46 AM
gogamid
6 odpowiedzi
28th Jan 2018, 8:13 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
https://code.sololearn.com/c6ErdwUmKLPK/?ref=app
28th Jan 2018, 8:51 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
#include <iostream> int main(){ int n1=0,n2=1,indexTo=20; while(indexTo--){ std::cout<<n1<<"\n"; n1+=n2; n1^=n2; n2^=n1; n1^=n2; } return 0; } //^= there for swap n1 and n2
28th Jan 2018, 8:55 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
@Gaurav actually fibonacci is part of my program. Answer you provided was modified by me, So i'm not so dumb to copy and paste your answer. Just couldn't think of algorithm, we are all humans after all. It happens. ANYWAY. THANK YOU, helped me a lot
28th Jan 2018, 9:13 AM
gogamid
28th Jan 2018, 9:20 AM
gogamid
+ 2
Couldn't
28th Jan 2018, 8:41 AM
gogamid