Get Answers to all your Questions

header-bg qa

Write a program to compute pow(x,y)

Answers (1)

best_answer

class GFG
    static int power(int x, int y)
    
        if (y == 0)
            return 1;
        else if (y % 2 == 0)
            return power(x, y / 2) * power(x, y / 2);
        else
            return x * power(x, y / 2) * power(x, y / 2);
    

    public static void main(String[] args)
    
        int x = 2;
        int y = 3;

        System.out.printf("0", power(x, y));
    

Posted by

Deependra Verma

View full answer