Write a C Program to Count the Number of Trailing Zeroes in Integer using bitwise operators.
Example: 12(1100)->2;
7(111) ->0.
Input-Output Format:
Input Consists of an Integer n. (n >0)
Refer Sample Input/ Output for Output format.
Sample Input and Output-I:
Enter an Integer:
12
There are 2 Trailing Zeros.
Sample Input and Output-II:
Enter an Integer:
7
There are no Trailing Zeros.
Program Code:
#include<stdio.h>
int main()
{
int n;
int count = 0;
printf("Enter an Integer:\n");
scanf("%d",&n);
while(1)
{
if((n&1)==1)
{
break;
}
count++;
n=n>>1;
}
if(count == 0)
{
printf("There are no Trailing Zeros. \n");
}
else
{
printf("There are %d Trailing Zeros.", count);
}
return 0;
}
Post A Comment:
0 comments: