Showing posts with label Binary Numbers Hacker Rank Solution in C. Show all posts
Showing posts with label Binary Numbers Hacker Rank Solution in C. Show all posts

Friday, 23 August 2019

Binary Numbers Hacker Rank Solution in C

 #include <stdio.h>
int main()
{
    int n,r,c=0,t=0;
    scanf("%d",&n);
    while(n>0)
    {
        r=n%2;
        if(r==1)
        {
            c++;
            if(c>t)
                t=c;
        }
        else
            c=0;
        n=n/2;
    }
    printf("%d",t);
    return 0;

}