;

C# program To Print The Binary Triangle


Tutorialsrack 29/11/2019 C# Programs

In this C# program, we will learn how to write a program to print the binary triangle.

Here is the code of the program to print the binary triangle:

Code - C# Program To Print The Binary Triangle
using System;

namespace Tutorialsrack
{
    class Program
    {
        /* C# program To Print Binary Triangle */
        static void Main(string[] args)
        {
            int last_Int = 0, rows;
            Console.Write("Enter the Number of Rows: ");
            rows = int.Parse(Console.ReadLine());
            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (last_Int == 1)
                    {
                        Console.Write("0");
                        last_Int = 0;
                    }
                    else if (last_Int == 0)
                    {
                        Console.Write("1");
                        last_Int = 1;
                    }
                }
                Console.Write("\n");
            }

            Console.ReadKey();
        }
    }
}
Output

Enter the Number of Rows: 5
1
01
010
1010
10101


Related Posts



Comments

Recent Posts
Tags