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

Given a piece of code int x[10]; int *ab; ab=x; To access the 6th element of the array which of the following is incorrect? (A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .

2 Answers   Oracle,


How can variables be characterized?

0 Answers  


Why static is used in c?

0 Answers  


what is difference between getchar,putchar functions and printf and scanf function? does putchar show output only when input given to it

5 Answers   DIT,


Explain what is dynamic data structure?

0 Answers  


Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage

7 Answers   Accenture,


main() { int i; for(i=0;i<5;i++) printf("%d",1l<<i); } why doesn't 'l' affect the code??????

1 Answers  


how to add our own function in c library please give details.?

1 Answers   TCS,


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

0 Answers  


write a program to display the numbers having digit 9 in the given range from 1 to 100

1 Answers  


What is extern keyword in c?

0 Answers  


What is the function of volatile in c language?

0 Answers  


Categories