Given an unsigned integer, find if the number is power of 2?

Answers were Sorted based on User's Feedback

Given an unsigned integer, find if the number is power of 2?..

main()
{
int i;
printf("Enter Number :");
scanf("%d",&i);
if(i&(i-1))
printf("Not atwo power");
else
printf("Two 's Power");
}

 Is This Answer Correct ? 5 Yes 0 No

Given an unsigned integer, find if the number is power of 2?..

main()
{
int i;
printf("Enter Number :");
scanf("%d",&i);
if(i&(i-1))
printf("Not atwo power");
else
printf("Two 's Power");
}

 Is This Answer Correct ? 3 Yes 0 No

Given an unsigned integer, find if the number is power of 2?..

#include<stdio.h>
void powerOfTwo(int number)
{
if(!(number & number-1) && number)
printf("\nthe number is a power of 2\n");
else printf("\nThe number is not a power of 2\n");
}

int main()
{
powerOfTwo(32); //power of 2
powerOfTwo(22); //not a power of 2
return 0;
}

 Is This Answer Correct ? 2 Yes 1 No

Given an unsigned integer, find if the number is power of 2?..

main()
{
unsigned int n;
printf("enter the number:\n");
scanf("%u",&n);
if(i&(i-1))
printf(" not power of two\n");
else
printf("power of two...\n");
}

 Is This Answer Correct ? 0 Yes 1 No

Given an unsigned integer, find if the number is power of 2?..

#include<stdio.h>
main()
{
int i,n,r=2
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i=r*i)
{
if(i==n)
{
r=0;
break;
}
}
if (r==0)
{
printf("power of two:");
}
else
{
printf("not power of two:");
}
getch();
}

 Is This Answer Correct ? 0 Yes 1 No

More C Interview Questions

How do you determine whether to use a stream function or a low-level function?

In C language what is a 'dangling pointer'?

How do I get an accurate error status return from system on ms-dos?

what is the role you expect in software industry?

How does #define work?

What is getch () for?

wat is output of the following int main() { const int j=2; int i; switch(i) { case 1:break; case j:break; default:break; } }

What is character set?

array of pointer pointer to array pointer to pointer

why programs in c are running with out #include<stdio.h>? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

What is static memory allocation?

Compare array data type to pointer data type

Categories
• C (4644)
• C++ (3460)
• VC++ (653)
• Delphi (566)
• Python Related (3238)
• PHP Related (7341)
• Scala (340)
• R Programming (396)
• Kotlin (184)
• Apache Groovy (39)
• Ruby (245)
• Go Programming Language (139)
• Objective-C (429)
• Programming Languages AllOther (736)