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
Explain how can I convert a number to a string?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
What is a volatile keyword in c?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
Calculate 1*2*3*____*n using recursive function??
How can I copy just a portion of a string?
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
Is c a great language, or what?
What are the back slash character constants or escape sequence charactersavailable in c?
Write a program to reverse a given number in c language?
What is merge sort in c?
What is C language ?
Is r written in c?
What is pragma c?
Write a program to find the biggest number of three numbers in c?