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

ATM machine and railway reservation class/object diagram

4795


Why c is a mother language?

552


What is #define?

569


What is the Purpose of 'extern' keyword in a function declaration?

644


What are the salient features of c languages?

619






What are global variables and how do you declare them?

611


What is a structure member in c?

536


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

739


Explain what are bus errors, memory faults, and core dumps?

784


Can variables be declared anywhere in c?

614


Which control loop is recommended if you have to execute set of statements for fixed number of times?

804


How can you find the day of the week given the date?

609


What is volatile keyword in c?

577


What are structures and unions? State differencves between them.

606


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.

1589