Write a function named bitcount that returns the number of 1

Write a function named bitcount that returns the number of 1-bit in the input argument that is an unsigned integer (contained in register $a0), and a test driver (main function) to test the function bitcount. The test driver prompts the user for a decimal unsigned integer, calls bitcount and then displays the result. For example, if the user gives 17 as the input, the program displays \"The number of 1-bit is 2\".

Thanks in advance!

Solution


#include<conio.h>
#include<stdio.h>

void main()
{


int num;
int count=0;
printf(\"Enter the number \");
scanf(\"%d\",&num);

count=bitcount(&num);
printf(\"The number of 1 bit is = %d\ \",count);

}
int bitcount(register int *$a0)
{


int count=0;
int temp;
while(*$a0>0)
{

if(*$a0%2==1)
{

count++;
}

*$a0=*$a0/2;

}
return count;
}

Write a function named bitcount that returns the number of 1-bit in the input argument that is an unsigned integer (contained in register $a0), and a test drive

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site