• Source
    1. /* Extended version of power function that can work
    2. for float x and negative y*/
    3. #include<stdio.h>
    4.  
    5. float power(float x, int y)
    6. {
    7. float temp;
    8. if( y == 0)
    9. return 1;
    10. temp = power(x, y/2);
    11. if (y%2 == 0)
    12. return temp*temp;
    13. else
    14. {
    15. if(y > 0)
    16. return x*temp*temp;
    17. else
    18. return (temp*temp)/x;
    19. }
    20. }
    21.  
    22. /* Program to test function power */
    23. int main()
    24. {
    25. float x = 2;
    26. int y = -3;
    27. printf("%f", power(x, y));
    28. return 0;
    29. }
    30.