Function to find the given number is a power of 2 or not?
Answer Posted / sujan.t
/* 100% correct answer */
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 is NOT A power of two");
Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
How can you convert integers to binary or hexadecimal?
why wipro wase
Define and explain about ! Operator?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What are the different types of constants?
What is array within structure?
Why static is used in c?
Write a program to know whether the input number is an armstrong number.
What is variable initialization and why is it important?
What is masking?
How can you determine the size of an allocated portion of memory?
What is the correct declaration of main?
You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.
How does pointer work in c?
Explain about the functions strcat() and strcmp()?