What will be the output for following 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;
}
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
Answer: Option D
Related Questions on Miscellaneous on Data Structures
Which data structure is used to implement a binary heap efficiently?
A. Array
B. Linked List
C. Stack
D. Queue
In which scenario would you use a Bloom Filter?
A. For implementing a stack-based algorithm
B. To maintain a balanced binary tree
C. For efficient sorting of elements
D. To test membership in a large dataset
A. Queue
B. Stack
C. Heap
D. Array

Join The Discussion