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

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

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

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