Printing total of 1's in binary number

This is a discussion on Printing total of 1's in binary number within the C Programming forums, part of the General Programming Boards category; I'm writing a program where the user enters an integer and the program should tell them how many ones are ...

Printing total of 1's in binary number

I'm writing a program where the user enters an integer and the program should tell them how many ones are in the binary form of the number. In the function I wrote, i need to use recursion. Here is what i have so far:
#include <stdio.h>

int binary( int number, int count2 )
{
int count;
if (number==0)
return count;
else
binary(number/2, count+number % 2)
count++;
}
Now I know i may be way off base here w/ what I have but please be gentle and dont give me crap. Atleast I posted some code. Any help anyone can offer me, would be greatly appreciated. Thank you

int binary( int number, int count )
{
if ( number==0 ) /* no more bits are set */
{
return count;
}
else /* we have some more bits somewhere */
{
if ( number % 2 ) /* if number is odd then the rightmost bit is set */
count++;