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
ATM machine and railway reservation class/object diagram
Why c is a mother language?
What is #define?
What is the Purpose of 'extern' keyword in a function declaration?
What are the salient features of c languages?
What are global variables and how do you declare them?
What is a structure member in c?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
Explain what are bus errors, memory faults, and core dumps?
Can variables be declared anywhere in c?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
How can you find the day of the week given the date?
What is volatile keyword in c?
What are structures and unions? State differencves between them.
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.