Function to find the given number is a power of 2 or not?
Answer Posted / rajiv malhotra
/* THIS SOLUTION IS 100% CORRECT */
#include<stdio.h>
int isPowerOf2(float n)
{
while(n>1)
{
n/=2.0;
}
return (n==1)?1:0; /* 1-> TRUE; 0-> FALSE*/
}
void main()
{
int x,n;
printf("enter a number\n");
fflush(stdin);
scanf("%d",&n);
x=isPowerOf2(n);
if(x==1)
printf("\n yes");
else
printf("\n no");
}
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
What is the difference between array and pointer in c?
How are strings stored in c?
What is a good data structure to use for storing lines of text?
What is output redirection?
i got 75% in all semester am i eligible for your company
Explain what are header files and explain what are its uses in c programming?
What is the difference between struct and typedef struct in c?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
What are the keywords in c?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
Why do we use int main instead of void main in c?
Can a pointer be volatile in c?
In a switch statement, what will happen if a break statement is omitted?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
Write a program to print factorial of given number without using recursion?