-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.java
More file actions
41 lines (37 loc) · 840 Bytes
/
recursion.java
File metadata and controls
41 lines (37 loc) · 840 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
import java .util.*;
public class recursion{
public static void number(int n){
if(n==0){
return;
}
number(n-1);
System.out.println(n);
}
public static int fab(int n){
if(n==0){
return 1;
}
return n*fab(n-1);
}
public static int sum(int n){
if(n==0){
return 0;
}
return n+sum(n-1);
}
public static int fib(int n){
if(n==0){
return 0;
}
if(n==1){
return 1;
}
return fib(n-1)+fib(n-2);
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.print("enter a number : ");
int n=sc.nextInt();
System.out.print(fib(n));
}
}