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


Please Help Members By Posting Answers For Below Questions

What is the description for syntax errors?

619


What is the purpose of ftell?

601


What is pointer to pointer in c language?

600


What is preprocessor with example?

591


What does malloc () calloc () realloc () free () do?

563






Explain what is the concatenation operator?

628


What is function definition in c?

590


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

736


What is the use of function in c?

715


What is unary operator?

662


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

710


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

817


What does & mean in scanf?

606


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

1427


What is the need of structure in c?

570