-
Notifications
You must be signed in to change notification settings - Fork 0
/
practical10.java
42 lines (35 loc) · 944 Bytes
/
practical10.java
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
import java.util.Scanner;
public class practical10 {
private static int temp = 1;
public static int fact(int a) {
if (a == 0 || a == 1) {
return 1;
} else {
return a * fact(a - 1);
}
}
public static int fib(int a) {
if (a == 0 || a == 1) {
return 1;
} else {
return a + fib(a - 1);
}
}
public static int count(int a) {
if (temp == a) {
return a;
} else {
System.out.println(temp);
temp++;
}
return count(a);
}
public static void main(String[] args) {
System.out.println("Program of recursion");
System.out.println("*********************");
Scanner sc = new Scanner(System.in);
System.out.println("ENTER A NO TO FIND FIBONACCI : -");
int a = sc.nextInt();
System.out.println(count(a));
}
}