summaryrefslogtreecommitdiff
path: root/tests/exec/pow_rec.cpp
blob: 5016246f1c68def631b3561fb160991208a09789 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

class Puiss {
public:
  int pow(int a, int n);
};

int Puiss::pow(int a, int n) {
  if (n <= 0)
    return 1;
  int r = pow(a, n / 2);
  r = r * r;
  if (n % 2 == 0)
    return r;
  return r * a;
}

int main() {
  Puiss p;
  std::cout << p.pow(2, 4) << "\n";
  std::cout << p.pow(6, 3) << "\n";
}