i have question how write program which calculates following procedures
i have exponential program which returns x^n here is code
public class Exp{
public static long exp(long x,long n){
long t=0;
if (n==0){
t= 1;
}
else{
if (n %2==0){
t= exp(x,n/2)* exp(x,n/2);
}
else{
t= x*exp(x,n-1);
}
}
return t;
}
public static void main(String[]args){
long x=5L;
long n=4L;
System.out.println(exp(x,n));
}
}
but how use it in Tetration program?please help
Tetration x ↑↑ n can be defined recursively as
So you could write
But notice that the tetration grows extremely fast, a
longis will not be big enough to store even 4 ↑↑ 3 (= 1.3 × 10154). Perhaps you need a BigInteger.(BTW,
expusually refers to the unary function ex, the binary function xy is usually calledpow.)