Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double power(double a, int n) {
- double x = 1;
- if (n > 0) {
- for (int i = 0; i < n; i++) {
- x *= a;
- }
- } else if (n < 0) {
- for (int i = 0; i < abs(n); i++) {
- x /= a;
- }
- }
- return x;
- }
- int main() {
- double ans;
- int n;
- cin >> ans >> n;
- cout << power(ans, n) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement