Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> int oneCount (char n); int main ( ) { printf (\"# 1-bits in b

ID: 3608691 • Letter: #

Question

#include <stdio.h>

int oneCount (char n);

int main ( ) {

   printf ("# 1-bits in base 2 rep of %u = %d ",

                                         0, oneCount((char)0));

   printf ("# 1-bits in base 2 rep of %u = %d ",

1, oneCount((char)1));

   printf ("# 1-bits in base 2 rep of %u = %d ",

8, oneCount((char)8));

   printf ("# 1-bits in base 2 rep of %u = %d ",

255, oneCount((char)255));

   return 0;

}

/* Your one count function goes here. */

int oneCount (char n)

{

      /* your code*/

     

}

Explanation / Answer

please rate - thanks I don't think you wanted you parameter a character. I changed it toan int and had to add the conio and getch to keep my DOS windowopen. I've highlighted the changes to your code #include #include int oneCount (int n); int main ( ) {    printf ("# 1-bits in base 2 rep of %u = %d ",0,oneCount(0));    printf ("# 1-bits in base 2 rep of %u = %d ",1,oneCount(1));    printf ("# 1-bits in base 2 rep of %u = %d ",8,oneCount(8));    printf ("# 1-bits in base 2 rep of %u = %d ",255,oneCount(255));    getch();    return 0; } /* Your one count function goes here. */ int oneCount (int n) {int count=0; while(n>0)    {if(n%2==1)        count++;     n=n/2;     } return count; }