Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- double pow(double a, unsigned int n) {
- double result = 1.;
- double a_in_power_of_2 = a;
- while (n) {
- if ((n & 1u) == 1u)
- result *= a_in_power_of_2;
- a_in_power_of_2 *= a_in_power_of_2;
- n >>= 1u;
- }
- return result;
- }
- int main() {
- double a = .0;
- unsigned int n = 0;
- std::cin >> a >> n;
- std::cout << pow(a, n);
- return 0;
- }
Add Comment
Please, Sign In to add comment