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, int );
int main()
{
int number2, c;
char x='y';
while (x=='y'||x=='Y') {
printf("Enter your number: \n");
scanf("%d", number2);
printf("Number of one bits in Binary: %d\n", binary(number2));
printf("Would you like to do another? ");
scanf("%c", x);
}
}
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