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
What is quick sort in c?
What does the function toupper() do?
Is there a way to compare two structure variables?
What is volatile, register definition in C
Explain how can I pad a string to a known length?
Is swift based on c?
What are the storage classes in C?
What is volatile variable in c with example?
Write a code to generate a series where the next element is the sum of last k terms.
what are the different storage classes in c?
What is the difference between ++a and a++?
Is file a keyword in c?
What is c value paradox explain?
Why does everyone say not to use scanf? What should I use instead?
Explain the difference between malloc() and calloc() function?