jump to navigation

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;
}else if(y>0){
return x*getpow(x,y)
}else if(y
return 1/x*getpow(x,y-1)
}
}

Comments»

1. aliahmad - November 3, 2006

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

2. aliahmad - November 3, 2006

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

3. essamabdelaziz - November 18, 2006

sorry man
actully i didn’t try it till now
just want to help others
anyway thank you for your feedback
Regards