What will be the output for following code? [code] float power(float x, int y) { float temp; if( y==0) return 1; temp = power(x,

Khánh Đoan

New member
What will be the output for following code?
Code:
float power(float x, int y) 
{ 
	float temp; 
	if( y==0) 
	return 1; 
	temp = power(x, y/2);	 
	if (y%2 == 0) 
		return temp*temp; 
	else
	{ 
		if(y > 0) 
			return x*temp*temp; 
		else
			return (temp*temp)/x; 
	} 
} 
int main() 
{ 
	float x = 2; 
	int y = -3; 
	printf("%f", power(x, y)); 
	return 0; 
}
A. Error
B. 1/4
C. 4
D. 0.25
 

Tìm kiếm

Back
Top