write a program to find out number of on bits in a number?

Answer Posted / naveen

//plz let me know whether it is correct or not...bcoz am just beginner
#include<stdio.h>

void main()
{

int j=0,i=0xFFFFE,temp=1;
int count=0;


while(j<=(sizeof(int)*8-1))
{

if(i&temp)
count++;
temp=temp<<1;
j++;
}
printf("%d",count);

}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is malloc calloc and realloc in c?

675


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1333


Is there any possibility to create customized header file with c programming language?

630


What are predefined functions in c?

572


Explain what are multibyte characters?

631






can anyone please tell about the nested interrupts?

1682


Write a program to check whether a number is prime or not using c?

580


How does struct work in c?

613


Suggesting that there can be 62 seconds in a minute?

603


to find the closest pair

1827


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

655


How can I send mail from within a c program?

587


The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.

1071


What does *p++ do? What does it point to?

621


What is the purpose of main( ) in c language?

628