Function to find the given number is a power of 2 or not?

Answer Posted / sujan

int n = 3;
boolean bool = true;
int reminder;
while (n >1)
{
reminder = n % 2;
if(reminder != 0)
{
bool = false;
break;
}
else
{
n = n / 2;
}
}
if (bool == true)
printf("The number is a power of two");
else
printf("The number "+ m + " is NOT A power of two");

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of realloc()?

676


How many header files are in c?

558


Is null always defined as 0(zero)?

618


Write the syntax and purpose of a switch statement in C.

631


What does the format %10.2 mean when included in a printf statement?

1093






main() { printf("hello"); fork(); }

699


How can I get back to the interactive keyboard if stdin is redirected?

673


What does sizeof function do?

618


Explain what is the benefit of using const for declaring constants?

618


What is the difference between array and linked list in c?

605


What do you mean by scope of a variable in c?

547


Can a variable be both constant and volatile?

564


What is identifiers in c with examples?

680


Does c have enums?

604


Why is c faster?

596