Determine if a number is a power of 2 at O(1).

Answers were Sorted based on User's Feedback



Determine if a number is a power of 2 at O(1)...

Answer / hary

int Isnopowerof2(int n)
{
if (n & n-1)
return 0;
return 1;
}

Is This Answer Correct ?    15 Yes 0 No

Determine if a number is a power of 2 at O(1)...

Answer / srinu naik

if((~n+1)& n ==n) printf("\n Given number is power of 2");
else printf("\Not the POwer of 2");

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

What is the purpose of scanf() and printf() functions?

0 Answers  


What does & mean in scanf?

0 Answers  


Difference between macros and inline functions? Can a function be forced as inline?

0 Answers   HAL, Honeywell, Zomato,


what is recursion in C

0 Answers   Cap Gemini,


What is a memory leak in structures? How can we rectify that?

2 Answers  






Explain the difference between exit() and _exit() function?

0 Answers  


what is the difference between const char *p, char const *p, const char* const p

5 Answers   Accenture, Aricent, CTS, Geometric Software, Point Cross, Verizon,


What is a lvalue

0 Answers   Global Logic,


how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12

0 Answers  


A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile

0 Answers  


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

0 Answers  


in C-programming language without using printf statement can we get output r not ? if yes how and if no also how ?

11 Answers   IBM,


Categories