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 a string?
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
Can we change the value of #define in c?
What is ponter?
What is New modifiers?
What is the sizeof () a pointer?
How to declare pointer variables?
What are c preprocessors?
Explain how can you restore a redirected standard stream?
Explain heap and queue.
What does the format %10.2 mean when included in a printf statement?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?
where are auto variables stored? What are the characteristics of an auto variable?