Last active
August 29, 2015 14:13
-
-
Save ahmedeshaan/ae291128456a4ed12a02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int multiplcation=1; | |
void power (int x, int n) { | |
if(n<0) { | |
n = n +(-n*2); | |
} | |
multiplcation *= x; | |
printf("%d \n",multiplcation); | |
if(n==0){ | |
return 1; | |
}else if (n==1) { | |
return x; | |
}else if(n%2==0) { | |
n = (2*n)/2; | |
}else if (n%2!=0) { | |
n = 2*(n-1)/2; | |
n++; | |
} | |
n--; | |
power(x,-n); | |
} | |
int main() | |
{ | |
power(2,5); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment