-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlogorecursive.java
More file actions
38 lines (33 loc) · 870 Bytes
/
Alogorecursive.java
File metadata and controls
38 lines (33 loc) · 870 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
public class Alogorecursive {
// public static int func(int x, int n) {
// if (n == 0)
// return 1;
// else if(n%2 == 0)
// return func(x*x, n/2);
// else
// return x*func(x*x, n/2);
// }
public static void main(String[] args){
factorial1(8);
}
// public static int func(int n) {
// if (n == 1)
// return 0;
// else
// return 1 + func(n/2);
// }
public static void factorial1(int n){
int factorial=1;
int index=1;
for(int i=0;i<=Math.pow(n,n);i++){
if(i==factorial*index){
factorial=i;
index+=1;
if(index==n+1){
System.out.println(factorial);
break;
}
}
}
}
}