summaryrefslogtreecommitdiff
path: root/1_anno/Programmazione_2/algorithms/pow.cc
blob: 16cf419142f3bb30f4754c7cce756d5df09f755c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>

using namespace std;

int pow(int x, int y) {
    int a = 1;
    
    for(int i = 0; i < y; ++i)
        a*=x;
    
    return a;
}


int pow2(int x, int y) {
    if(y < 1) return 1;
    
    return x*pow(x, y-1);
}

int main() {
    cout << pow(2, 5) << endl;
    cout << pow2(2, 5) << endl;
    return 0;
}