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;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: