Answer the question
In order to leave comments, you need to log in
Is the result correct?
Binary exponentiation algorithm for long numbers.
double binpow (double number, long int power)
{
double res = 1;
while (power)
if (power & 1)
{
res *= number;
--power;
}
else
{
number *= number;
power >>= 1;
}
std::cout << "Result: " << res;
}
int main()
{
double a;
long int n;
std::cout << "Input number: ";
std::cin >> a;
std::cout << "Input power: ";
std::cin >> n;
binpow (a, n);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question