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

In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

1614


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

885


Differentiate abs() function from fabs() function.

797


What is p in text message?

747


code for find determinent of amatrix

1741


What happens if a header file is included twice?

806


How can I open a file so that other programs can update it at the same time?

913


Describe newline escape sequence with a sample program?

885


`write a program to display the recomended action depends on a color of trafic light using nested if statments

1897


What is a pointer in c?

996


What is the advantage of an array over individual variables?

991


int i=10; printf("%d %d %d", i, i=20, i);

1307


What is the correct declaration of main?

911


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

1146


Is array name a pointer?

822