Fibonacci Series in c++:
1. Let 3 variables a, b, sum
2. initialize them as a = 0, b = 1, sum = 0.
3. loop n = 8 times using for loop.
4. if(i==1) print a and skip the loop.
5. if(i==12) print b skip the loop.
Below arrangements explains the scenario:-
n a [a = b] b [b = sum] sum [sum = a + b]
3 0 1 0 + 1 = 1
2 1 1 1 + 1 = 2
5 1 2 2 + 1 = 3
6 2 3 3 + 2 = 5
7 3 5 3 + 5 = 8
8 5 8 3 + 5 = 13
and so on..
Comments
Post a Comment