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
What is wrong in this statement?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
How can I split up a string into whitespace-separated fields?
Can you add pointers together? Why would you?
What are the types of c language?
Write a code to generate a series where the next element is the sum of last k terms.
What is bss in c?
simple program of graphics and their output display
Describe the order of precedence with regards to operators in C.
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
Difference between strcpy() and memcpy() function?
How can you restore a redirected standard stream?
What are structures and unions? State differencves between them.
State two uses of pointers in C?