Given an unsigned integer, find if the number is power of 2?
Answer Posted / 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 View All Answers
Add Two Numbers Without Using the Addition Operator
Why doesnt that code work?
Should I learn data structures in c or python?
What are dangling pointers in c?
Write a program to reverse a string.
What is data structure in c language?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
What is the purpose of the preprocessor directive error?
Is there a way to compare two structure variables?
All technical questions
What are 'near' and 'far' pointers?
What are header files in c?
Why is it that not all header files are declared in every C program?
C program to find all possible outcomes of a dice?
What are the features of c language?