calculate x power y using recursion October 3, 2006
Posted by essamabdelaziz in Uncategorized.trackback
public double getpow(double x,double y){
if(y==0)
{
return x;
return x;
}else if(y>0){
return x*getpow(x,y)
}else if(y
return 1/x*getpow(x,y-1)
}
}
}
hello essam,
congratulations for your nice blog.
sorry for saying to you that these methof is wrong in semanitcs and made infinite loop!!
let us deal with it in detail
if(y==0)return x;
//how?
2^0=1 am not i right?
make it
if(y==0)return 1;
//////////////////
if(y>0)return x*pow(x,y);
is not that an inifinte loop?
you say
if(2>0)then x*pow(x,2);
when this condition breaks?
make it
if(y>0)return x*pow(x,y-1);
////////////////////////////
if(y
hello essam,
congratulations for your nice blog.
sorry for saying to you that these methof is wrong in semanitcs and made infinite loop!!
let us deal with it in detail
if(y==0)return x;
//how?
2^0=1 am not i right?
make it
if(y==0)return 1;
//////////////////
if(y>0)return x*pow(x,y);
is not that an inifinte loop?
you say
if(2>0)then x*pow(x,2);
when this condition breaks?
make it
if(y>0)return x*pow(x,y-1);
////////////////////////////
if(y
sorry man
actully i didn’t try it till now
just want to help others
anyway thank you for your feedback
Regards