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
how to write optimum code to divide a 50 digit number with a 25 digit number??
Are the outer parentheses in return statements really optional?
What does void main () mean?
what do u mean by Direct access files? then can u explain about Direct Access Files?
What is external variable in c?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Explain what is wrong in this statement?
Explain the advantages and disadvantages of macros.
Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent
What is use of #include in c?
What is meant by recursion?
What is volatile variable in c?
What is volatile c?
How many types of operator or there in c?
What is omp_num_threads?