31 lines
590 B
C++
31 lines
590 B
C++
#include <iostream>
|
|
#include <cstdint> // for std::int64_t
|
|
#include <cassert> // for assert
|
|
|
|
std::int64_t powint(std::int64_t base, int exp)
|
|
{
|
|
assert(exp >= 0 && "powint: exp parameter has negative value");
|
|
|
|
std::int64_t result{ 1 };
|
|
while (exp)
|
|
{
|
|
if (exp & 1) {
|
|
std::cout << "a : " << result << "\n";
|
|
result *= base;
|
|
}
|
|
std::cout << "b : " << exp << "\n";
|
|
exp >>= 1;
|
|
std::cout << "c : " << base << "\n";
|
|
base *= base;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
std::cout << powint(7, 12); // 7 to the 12th power
|
|
|
|
return 0;
|
|
}
|