Given an unsigned integer, find if the number is power of 2?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
How do you redirect a standard stream?
what is the output on the screen? int n; n=printf("my name is %d",printf("kiran %d",printf("kumar"))); printf("\n %d \n",n);
Which weighs more, a gram of feathers or a gram of gold?
Explain how can I open a file so that other programs can update it at the same time?
What is function prototype?
how to implement stack operation using singly linked list
hello friends what do u mean by BUS ERROR i got this error while i am doing my program in DATA STRUCTURES
Explain what does the function toupper() do?
How can draw a box in cprogram without using graphics.h header file & using only one printf(); ?
Do you know what are bitwise shift operators in c programming?
Write a program to print fibonacci series without using recursion?
What is use of #include in c?