Wednesday, July 30, 2008

C Source code for checking if a number is power of 2

void root( int & nn) {
nn = nn/2;
}

int PowerOf2() {

int n ;
char ch='q';

do {

printf("\nEnter No: ");
scanf("%d",&n);
if((n & n-1) == 0) {

int temp =n;
while(temp >0 && temp%2 ==0 ) {

printf(" %d *", temp);
root(temp);
}
}
else {

printf("\n No is not a power of 2.");
}
printf("\nDo you want to continue.... :");
scanf("%c", &ch);
}while(ch!='q');

return 0;
}

No comments:

Your Title