[ create a new paste ] login | about

Link: http://codepad.org/PyXPJ00W    [ raw code | output | fork ]

C, pasted on Nov 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

int power(int x, int y)
{
         if (y == 0)     return 1;
    else if (y % 2 == 0) return power(x * x, y / 2);
    else                 return x * power(x * x, y / 2);
}

int main(void)
{
    int x = 2, y = 16;

    printf("x^y = %d\n", power(x, y));
    return 0;
}


Output:
1
x^y = 65536


Create a new paste based on this one


Comments: