Enter the number: 5
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0
1 0 1 0 1
0 1 0
1
class Program
{
static void Main(string[] args)
{
int ro, cl, tp, no, k = 1;
Console.WriteLine("Enter a value : ");
no = int.Parse(Console.ReadLine());
tp = no;
for (ro = 0; ro < no; ro++)
{
for (cl = 0; cl < ro; cl++)
{
Console.Write(" ");
}
for (cl = 0; cl < (tp * 2 - 1); cl++)
{
if (k % 2 == 0)
{
Console.Write(" 0");
k++;
}
else
{
Console.Write(" 1");
k++;
}
}
Console.WriteLine("");
tp--;
}
Console.ReadLine();
}
}
}
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0
1 0 1 0 1
0 1 0
1
class Program
{
static void Main(string[] args)
{
int ro, cl, tp, no, k = 1;
Console.WriteLine("Enter a value : ");
no = int.Parse(Console.ReadLine());
tp = no;
for (ro = 0; ro < no; ro++)
{
for (cl = 0; cl < ro; cl++)
{
Console.Write(" ");
}
for (cl = 0; cl < (tp * 2 - 1); cl++)
{
if (k % 2 == 0)
{
Console.Write(" 0");
k++;
}
else
{
Console.Write(" 1");
k++;
}
}
Console.WriteLine("");
tp--;
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment