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
What is the use of static variable in c?
What are the types of type qualifiers in c?
What is a file descriptor in c?
how can f be used for both float and double arguments in printf? Are not they different types?
What is void pointers in c?
What are inbuilt functions in c?
How can you determine the maximum value that a numeric variable can hold?
what does static variable mean?
What are logical errors and how does it differ from syntax errors?
What is a constant and types of constants in c?
Why c is called a middle level language?
Why n++ execute faster than n+1 ?
How can you increase the size of a statically allocated array?
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
What is the use of bit field?