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

#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

Explain how can I convert a number to a string?

652


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

712


What is a volatile keyword in c?

639


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

565


Calculate 1*2*3*____*n using recursive function??

1522






How can I copy just a portion of a string?

820


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

617


Is c a great language, or what?

606


What are the back slash character constants or escape sequence charactersavailable in c?

690


Write a program to reverse a given number in c language?

623


What is merge sort in c?

649


What is C language ?

1533


Is r written in c?

727


What is pragma c?

619


Write a program to find the biggest number of three numbers in c?

590