diff --git a/power b/power new file mode 100644 index 0000000..92704da --- /dev/null +++ b/power @@ -0,0 +1,23 @@ + +#include + +/* Function to calculate x raised to the power y */ +int power(int x, unsigned int y) +{ + if (y == 0) + return 1; + else if (y%2 == 0) + return power(x, y/2)*power(x, y/2); + else + return x*power(x, y/2)*power(x, y/2); +} + +/* Program to test function power */ +int main() +{ + int x = 2; + unsigned int y = 3; + + printf("%d", power(x, y)); + return 0; +}