52.write a “Hello World” program in “c” without using a
semicolon?
53.Give a method to count the number of ones in a 32 bit number?
54.write a program that print itself even if the source file
is deleted?
55.Given an unsigned integer, find if the number is power of 2?
Answer Posted / lokesh n. jaliminche
/*program to check if number is power of 2
#include <stdio.h>
unsigned int check_power(unsigned int value)
{
unsigned int count = 0;
while (value > 0) {
if ((value & 1) == 1)
count++;
value >>= 1;
}
return count;
}
int main()
{
unsigned int n, count;
printf("Enter the number \n");
scanf("%d",&n);
count=check_power(n);
if(count == 1)
{
printf("number is power of 2\n");
}
else
{
printf("number is not power of 2\n");
}
printf("set bits == %d",count);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why can't I perform arithmetic on a void* pointer?
Explain what is the difference between #include and #include 'file' ?
What is break statement?
What is assert and when would I use it?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What are valid signatures for the Main function?
Write a program to swap two numbers without using the third variable?
Is javascript based on c?
What is operator promotion?
Why do we use pointer to pointer in c?
What are types of functions?
What are pointers?
What are the disadvantages of c language?
how many errors in c explain deply
Do you have any idea about the use of "auto" keyword?