Function to find the given number is a power of 2 or not?
Answer Posted / s.v.prasad reddy,lifetree conv
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int num,i=0,flag;
clrscr();
printf("\nEnter the number:=");
scanf("%d",&num);
if(num==0 || num==1 || (num%2)!=0) /* Validation Part */
{
printf("\n We can't express the given number to power
of 2");
return;
}
for(;;}
{
if(pow(2,i)==num)
{
flag=1;
break;
}
if(pow(2,i)>num)
{
flag=0;
break;
}
i++;
}
if(falg==1)
printf("\n %d number is 2 power of %d",num,i);
else
printf("\n%d number can't be expressed as power of 2",num);
getch();
}
Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
how to create duplicate link list using C???
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
How to explain the final year project as a fresher please answer with sample project
Which are low level languages?
Why doesnt this code work?
write a program in c language to print your bio-data on the screen by using functions.
Do pointers take up memory?
Why main is not a keyword in c?
What are the types of data types and explain?
What is masking?
What is the use of define in c?
What is structure padding in c?
Define VARIABLE?
What is a volatile keyword in c?
Write a program on swapping (100, 50)