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?..

Answer / veerendra jonnalagadda

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?..

Answer / veerendra jonnalagadda

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?..

Answer / coder

#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?..

Answer / asis bera

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?..

Answer / sagar shah

#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

Post New Answer



More C Interview Questions

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

0 Answers  


In C language what is a 'dangling pointer'?

0 Answers   Accenture,


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

0 Answers  


what is the role you expect in software industry?

0 Answers   HCL,


How does #define work?

0 Answers  






What is getch () for?

0 Answers  


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

2 Answers  


What is character set?

0 Answers  


array of pointer pointer to array pointer to pointer

1 Answers   MAHINDRA,


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 "); }

0 Answers  


What is static memory allocation?

0 Answers  


Compare array data type to pointer data type

0 Answers  






Categories