Wednesday, 28 October 2015

C# Program to Print a BinaryTriangle??

class BinaryTriangle
    {
        public static void Main(String[] args)
        {
            int k, lastInt = 0, input;
            Console.WriteLine("Enter the Number of Rows : ");
            input = int.Parse(Console.ReadLine());
            for (int j = 1; j <= input; j++)
            {
                for (k = 1; k <= j; k++)
                {
                    if (lastInt == 1)
                    {
                        Console.Write("0");
                        lastInt = 0;
                    }
                    else if (lastInt == 0)
                    {
                        Console.Write("1");
                        lastInt = 1;
                    }
                } Console.Write("\n");
            }
            Console.ReadLine();
        }
    }
}
---------------------
OUTPUT
Enter the Number of Rows : 6
1
01
010
1010
10101
101010
----------------

1 comment:

  1. its really good article, thanks and keep update it. :)

    ReplyDelete