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

while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

991


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

1041


What is calloc() function?

858


What is function and its example?

898


What is the use of typedef in structure in c?

723


what is uses of .net

1468


write a proram to reverse the string using switch case?

2685


What is meant by operator precedence?

883


The statement, int(*x[]) () what does in indicate?

896


What does 3 periods mean in texting?

812


What is the difference between text and binary modes?

876


i have a written test for microland please give me test pattern

2481


What does sizeof function do?

873


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3948


Explain how do you print only part of a string?

930