Power of a Number using Recursion in Java
Login/Signup to comment
3 comments on “Power of a Number using Recursion in Java”
×
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
Login/Signup to comment
Get Hiring Updates right in your inbox from PrepInsta
package recurtion;
public class PowerofNumber {
public static int Powerof(int base,int pow)
{
if(pow==0)
{
return 1;
}
return (base*Powerof(base, (pow-1)));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int n1=5;
int n2=3;
System.out.println(Powerof(n1,n2));
}
}
Kindly join our Discord channel for all the technical doubts.
Using one argument-
public static int rec(int n){
if(p==1){
return n;
}
p–;
return n*rec(n);
}