Can anyone write me a program usin C++ and loops to get the outputs 0,1,1,2,3,5,8,13,21,34,55. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone write me a program usin C++ and loops to get the outputs 0,1,1,2,3,5,8,13,21,34,55.

The no.s start from 0 and every 3rd no. is the sum of the 2 previous no.s.

13th Sep 2017, 10:58 AM
Anand Benny
3 Answers
+ 5
unsigned long long u1 = 1, u0 = 0; while(u0 < 55){ cout << u0 << ','; u0 = (u1+=u0) - u0; } cout << u0 << endl;
13th Sep 2017, 11:04 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
13th Sep 2017, 1:10 PM
RZK 022
RZK 022 - avatar
0
that is called fibonacci series
13th Sep 2017, 11:26 AM
Suhail Pappu
Suhail Pappu - avatar