Function to find the given number is a power of 2 or not?
Answer Posted / santhi perumal
#include<stdio.h>
#include<conio.h>
int main()
{
int i,count = 0,number;
printf("Enter the number\n");
scanf("%d",&number);
for(i=15;i>=0;i--)
{
if((1<<i) & number)
count++;
}
if(count == 1)
printf("\nThe Given Number is Power of 2\n");
else
printf("\nThe Given Number is Not Power of 2\n");
}
Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
What is the description for syntax errors?
What is the purpose of ftell?
What is pointer to pointer in c language?
What is preprocessor with example?
What does malloc () calloc () realloc () free () do?
Explain what is the concatenation operator?
What is function definition in c?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is the use of function in c?
What is unary operator?
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
What does & mean in scanf?
Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers
What is the need of structure in c?