Computer Science, asked by kumarnirmal447, 6 months ago

write a Python program for given two integers x and n, compute x
^n.​

Answers

Answered by jack4610
48

Answer:

x = int(input("Enter base number:"))

n=int(input("Enter exponent:"))

z=x**n

print(z)

Explanation:

Hope it helps !

Answered by steffiaspinno
0

Input: x = 3, n = 2

Output: 9

C++

#include<iostream>  // to compute x^n

using namespace std;

class compute

{

public:

int pow(int x, unsigned int n) // function for x raised to the power n

{

   if (n == 0)

       return 1;

   else if (n % 2 == 0)

       return pow(x, n / 2) * pow(x, n / 2);

   else

       return x * pow(x, n / 2) * pow(x, n / 2);

}

};

 

int main()

{

   compute a;

   int x = 3;

   unsigned int n = 2;

 

   cout << a.pow(x, n);

   return 0;

}

Similar questions