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 is the difference between abs() and fabs() functions?
What are the types of i/o functions?
Can a file other than a .h file be included with #include?
Why #include is used in c language?
What is the difference between fread buffer() and fwrite buffer()?
What is #line in c?
In a header file whether functions are declared or defined?
What is c system32 taskhostw exe?
Where in memory are my variables stored?
Explain what are the advantages and disadvantages of a heap?
What is pointer to pointer in c?
What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?
What is c basic?
Explain what is a program flowchart and explain how does it help in writing a program?
Difference between exit() and _exit() function?