File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ public class Recursion {
3
+
4
+ //First Logic
5
+
6
+ int Fibonacci (int fibo )
7
+ {
8
+ if (fibo <=1 )
9
+ {
10
+ return fibo ;
11
+ }
12
+ else
13
+ {
14
+ return Fibonacci (fibo -1 )+Fibonacci (fibo -2 );
15
+ }
16
+
17
+ }
18
+
19
+ public static void main (String [] args ) {
20
+ // TODO Auto-generated method stub
21
+ //Object Created
22
+ Recursion R1 = new Recursion ();
23
+
24
+ int n =10 ;
25
+
26
+ System .out .println ("\n \t \t \t First Logic \n " );
27
+
28
+ for (int i =0 ;i <=n ;i ++)
29
+ {
30
+ System .out .print (R1 .Fibonacci (i )+" " );
31
+ }
32
+
33
+ System .out .println ("\n \n \t \t \t Second Logic \n " );
34
+
35
+ int f1 =0 ,f2 =1 ,sum ;
36
+ for (int i =0 ;i <=n ;i ++)
37
+ {
38
+
39
+ if (i <=1 )
40
+ {
41
+ System .out .print (i +" " );
42
+ }
43
+ else
44
+ {
45
+ sum =f1 +f2 ;
46
+ f1 =f2 ;
47
+ f2 =sum ;
48
+ System .out .print (sum +" " );
49
+ }
50
+
51
+ }
52
+
53
+
54
+ }
55
+
56
+ }
You can’t perform that action at this time.
0 commit comments