Function to find the given number is a power of 2 or not?
Answer Posted / sagar bhagat
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,flag=0,temp;
clrscr();
printf("\nEnter the number=");
scanf("%d",&num);
if(num<=0)
printf("Plz enter anoter num");
else
{
temp=num;
for(i=1;(i<num) ;i++)
{
if((i*i)==temp)
{
flag=1;
break;
}
}
}
if(flag==1)
printf("\nNumber %d is in power of 2 of %d",num,i);
else
printf("\nNumber %d is not in power of 2 ",num);
getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are different types of operators?
Can an array be an Ivalue?
What is the difference between array and pointer?
why do some people write if(0 == x) instead of if(x == 0)?
What is signed and unsigned?
What is c method?
Explain what is the best way to comment out a section of code that contains comments?
Can a file other than a .h file be included with #include?
What are types of structure?
What are the uses of a pointer?
What is break in c?
Why array is used in c?
What are logical errors and how does it differ from syntax errors?
Is it better to bitshift a value than to multiply by 2?
What is selection sort in c?