Search Your Query

Breaking

Sunday, July 14, 2019

Write A C Program To Count The Number Of 0's In The Binary Reprasentation

Using Bitwise Operator Write A C Program To Count The Number Of 0's In The Binary Reprasentation Of An Integer

Program Code:

#include<stdio.h>
int main()
{
unsigned int n;
int count=0;
printf("Enter the vaue of n\n");
scanf("%d",&n);
while(n!=0)
{
if((n&1)==1)
break;
n=n>>1;
count++;
}
printf("number of 0's are-->%d\n",count);
return 0;

}

Input:

Enter the value of n
12

Output:

number of 0's are-->2

No comments:

Post a Comment