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

Answer Posted / jessu srikanth

int isPowerOf2(unsigned int n)
{
float r=n;
while(r>1) r/=2.0;
return (r==1)?1:0; /* 1-> TRUE; 0-> FALSE*/
}

Is This Answer Correct ?    9 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know the difference between exit() and _exit() function in c?

612


What is meant by gets in c?

613


Why clrscr is used in c?

592


What does #pragma once mean?

693


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

664






What is bash c?

563


What is typeof in c?

611


Compare and contrast compilers from interpreters.

685


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

1911


Explain how do you list a file’s date and time?

621


What is the purpose of sprintf?

625


Explain the properties of union. What is the size of a union variable

720


What are pointers really good for, anyway?

621


Explain what will the preprocessor do for a program?

607


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

567