-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecursioneg.java
More file actions
47 lines (35 loc) · 774 Bytes
/
recursioneg.java
File metadata and controls
47 lines (35 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.codingblocks.Lec7;
public class recursioneg {
public static void main(String[] args) {
int n=3;
printinc(n);
System.out.println(fact(3));
System.out.println(fibo(5));
}
public static void printdec(int n){
if(n==0){
return;
}
System.out.println(n);
printdec(n-1);
}
public static void printinc(int n){
if(n==0){
return;
}
printinc(n-1);
System.out.println(n);
}
public static int fact(int n){
if(n==0){
return 1;
}
return n*fact(n-1);
}
public static int fibo(int n){
if(n<2){
return n;
}
return fibo(n-1)+fibo(n-2);
}
}