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
Write a program to identify if a given binary tree is balanced or not.
What are the 4 types of unions?
How to write c functions that modify head pointer of a linked list?
Can a pointer be null?
What is c value paradox explain?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
What are predefined functions in c?
What is the best organizational structure?
Why is structure important for a child?
Is it better to bitshift a value than to multiply by 2?
For what purpose null pointer used?
Explain heap and queue.
What is bin sh c?
What is memcpy() function?
What is the use of ?