Thanks! But it doesn't seem to get any output? Please advise.
Anything i should input to show output like f(5) = 5?
Thanks.
what output are you expecting? your program does not contain any code to print anything on the screen. For C programs use printf() function, c++ programs use cout class. See your text book for instructions about how to use these functions.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>Is it something like this?
I don't know. You have not said what you want it to look like yet. You should compile and run your program to see for yourself whether it is right or not.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The problem is that your program has several compiler errors and is badly formatted. Here is a correction
#include <stdio.h>
int bitcount(unsigned x);
int main(void)
{
printf("%d\n",bitcount(3));
return 0;
}
int bitcount(unsigned x)
{
int b;
for (b=0; x!=0; x >>=1)
{
if (x &01)
{
b++;
}
}
return b;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343