Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 09 / task2.cpp
blob: e52d12d2febab46bbd336ad09c603e04fcbaa34f (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
//Way 1
unsigned Pow(unsigned x, unsigned n)
{
	if (n != 0)
		return x * Pow(x, n - 1);

	return 1;
}

//Way 2 - more optional
unsigned power(unsigned x, unsigned n)
{
	if (n == 0)
		return 1;

	if (n % 2 == 1)
		return x * power(x, n - 1);
	else
	{
		unsigned temp = power(x, n / 2);
		return temp * temp;
	}
}