How to find fibonacci series till 13 using for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to find fibonacci series till 13 using for loop?

21st Aug 2017, 11:20 AM
Akshat Agarwal
Akshat Agarwal - avatar
10 Answers
24th Aug 2017, 10:50 AM
hamletmun
hamletmun - avatar
+ 8
@Akshat Nothing, its an escape character for an indentation tab, you could remove it.
21st Aug 2017, 11:39 AM
Dev
Dev - avatar
+ 7
int a = 1, b = 1; for (int i = 1; i < 8; i++) { System.out.print (a+"\t"); int res = a+b; a = b; b = res; }
21st Aug 2017, 11:32 AM
Dev
Dev - avatar
+ 6
The Fibonacci sequence itself is built upon the concept of recursion.
22nd Aug 2017, 8:42 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
thanks👍
21st Aug 2017, 11:44 AM
Akshat Agarwal
Akshat Agarwal - avatar
+ 3
So what is Fibonacci's numbers? 1, 1, 2, 3, 5, 8, 13 Let's start simple: 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 A + B = C Now if you look carefully you can see that in this sequence Fibonacci is repeated: - At A it starts 0, 1, 1, 2... - At B it starts 1, 1, 2, 3.... - At C it starts 1, 2, 3, 5.... With this we see that we want B's values. int a = 0; int b = 1; int c = a + b; We want a and b to change the whole time so we put it in a for loop: int a = 0; int b = 1; int c = 1; while ( b <= 13){ // While B is smaller-equal to 13 System.out.print(b); a = b; c = a + b; b = c; } Then we move everything up. 0 + 1 = 1; a + b = c; then a = 1 because b is 1, b = 1 because c is 1, c = 2 because a + b is 2
21st Aug 2017, 12:59 PM
Limitless
Limitless - avatar
+ 2
what's the use of taking '/t' here?
21st Aug 2017, 11:35 AM
Akshat Agarwal
Akshat Agarwal - avatar
+ 2
Here is something that can maybe help you https://code.sololearn.com/cCT1D9J4T9zQ/?ref=app
21st Aug 2017, 12:40 PM
Limitless
Limitless - avatar
+ 2
can you just explain a little about that.😐
21st Aug 2017, 12:48 PM
Akshat Agarwal
Akshat Agarwal - avatar
17th Nov 2017, 1:39 AM
#RahulVerma
#RahulVerma - avatar