Skip to content

Instantly share code, notes, and snippets.

@ahmedeshaan
Last active August 29, 2015 14:13
Show Gist options
  • Save ahmedeshaan/ae291128456a4ed12a02 to your computer and use it in GitHub Desktop.
Save ahmedeshaan/ae291128456a4ed12a02 to your computer and use it in GitHub Desktop.
#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