Fibonacci series
Fibonacci series is adding a previous two number to form a new number.
Example-1:
Input : n = 5 Output : 0 1 1 2 3
Example-2:
Input : n = 4 Output : 0 1 1 2
Solution
public class Main { public static void main(String [] args) { int n = 5; int a = 0; int b = 1; int c; for(int i=1; i<=n; i++) { System.out.print(a+" "); c = a+b; a = b; b = c; } } }
n = 5 a = 0 b = 1 for i in range(1,n+1): print(a,end=" ") c = a+b a = b b = c
Output
0 1 1 2 3