write a Python program for given two integers x and n, compute x
^n.
Answers
Answered by
48
Answer:
x = int(input("Enter base number:"))
n=int(input("Enter exponent:"))
z=x**n
print(z)
Explanation:
Hope it helps !
Answered by
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
Hindi,
3 months ago
Computer Science,
3 months ago
Math,
3 months ago
CBSE BOARD XII,
6 months ago
English,
11 months ago
Math,
11 months ago