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


Please Help Members By Posting Answers For Below Questions

Why can't I perform arithmetic on a void* pointer?

646


Explain what is the difference between #include and #include 'file' ?

593


What is break statement?

649


What is assert and when would I use it?

591


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

684






What are valid signatures for the Main function?

707


Write a program to swap two numbers without using the third variable?

610


Is javascript based on c?

601


What is operator promotion?

637


Why do we use pointer to pointer in c?

610


What are types of functions?

575


What are pointers?

642


What are the disadvantages of c language?

632


how many errors in c explain deply

1637


Do you have any idea about the use of "auto" keyword?

673