programming-examples/c-sharp/Basic/C# Program to Print a BinaryTriangle.cs
2019-11-18 14:44:36 +01:00

46 lines
1.1 KiB
C#

/*
* C# Program to Print a BinaryTriangle
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class Program
{
public static void Main(String[] args)
{
int p, lastInt = 0, input;
Console.WriteLine("Enter the Number of Rows : ");
input = int.Parse(Console.ReadLine());
for (int i = 1; i <= input; i++)
{
for (p = 1; p <= i; p++)
{
if (lastInt == 1)
{
Console.Write("0");
lastInt = 0;
}
else if (lastInt == 0)
{
Console.Write("1");
lastInt = 1;
}
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
/*
Enter the Number of Rows : 5
1
01
010
1010
10101