summaryrefslogblamecommitdiff
path: root/tests/exec/pow_loop.cpp
blob: 1af58614b1b813d0795630f17e3f396974bf541e (plain) (tree)






















                                   
#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";
}