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:
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();
}
}
}
Enter the Number of Rows: 5
1
01
010
1010
10101
Comments