• + 0 comments

    C#

        int n = Convert.ToInt32(Console.ReadLine().Trim());
        int count = 0;
        int max = 0;
    
        var bin = Convert.ToString(n, 2);
    
        for(int number = 0; number < bin.Length; number++)
        {
            if(bin[number] == '1')
            {
                count++;
            }
            else
            {
                count = 0;
            }
    
            if(count > max) max = count;
        }
    
        Console.WriteLine(max);