-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerofnum
More file actions
37 lines (34 loc) · 725 Bytes
/
Copy pathpowerofnum
File metadata and controls
37 lines (34 loc) · 725 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
// stack falling return type
public class test1 {
public static int Calpow(int x,int n){
if(n==0){
return 1;
}
if(x==0){
return 0;
}
int xpownm1= Calpow(x, n-1);
int xpow=x*xpownm1;
return xpow;
}
public static void main(String[] args){
int x=2;
int n=3;
int result= Calpow(x,n);
System.out.println(result);
}
}
//Using Stack builder
public class powerofnum{
public static void power(int num,int pow,int result) {
if(pow==0) {
System.out.println(result);
return;
}
result=result*num;
power(num,pow-1,result);
}
public static void main(String[] args) {
power(2,5,1);
}
}