Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


Find if a number is power of two or not?



Find if a number is power of two or not?..

Answer / om

int f(int num)
{

if(( num>0) && (!(num & (num-1))) )
return 1;
else
return 0;
}
// f(16)...... 16 & 15 = 10000 & 01111 =00000
f(4) ...... 4 & 3 =0100 & 0111 =0000

f(11).......11 & 10 = 1011 & 1010 = 1010 so not...
f(12).......12 & 11 = 1100 & 1011 = 1000 so not...

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More C Interview Questions

What is the scope of local variable in c?

0 Answers  


what is op? for(c=0;c=1000;c++) printf("%c",c);

21 Answers   Trigent,


In a byte, what is the maximum decimal number that you can accommodate?

0 Answers  


What is the difference between printf and scanf )?

0 Answers  


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

0 Answers  






define function

4 Answers   Assurgent, Sonata,


What is null character in c?

0 Answers  


What is the role of && operator in a program code?

0 Answers  


what will the following program do? void main() { int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1

1 Answers   IBM,


Explain the term printf() and scanf() used in c language?

0 Answers  


biggest of two no's with out using if condition statement

5 Answers  


#include<stdio.h> #include<conio.h> void main() { float a; clrscr(); a=0.5; if(a==0.5) printf("yes"); else printf("no"); getch(); }

9 Answers   TCS,






Categories