From a60e8a8eabde116cc3da920b637bc4f6f5b8b17c Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Thu, 5 Dec 2013 22:21:11 +0100 Subject: Added tests. --- tests/exec/pow_rec.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/exec/pow_rec.cpp (limited to 'tests/exec/pow_rec.cpp') diff --git a/tests/exec/pow_rec.cpp b/tests/exec/pow_rec.cpp new file mode 100644 index 0000000..5016246 --- /dev/null +++ b/tests/exec/pow_rec.cpp @@ -0,0 +1,22 @@ +#include + +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"; +} -- cgit v1.2.3