Enter the number : 5
1
2 4
1 3 5
2 4 6 8
1 3 5 7 9
class Program
{
static void Main(string[] args)
{
int temp=0;
Console.WriteLine("Enter the number");
int n = int.Parse(Console.ReadLine());
for(int row=0;row<=n;row++)
{
if(row%2==0)
{
temp = 2;
}
else
{
temp = 1;
}
for(int coll=1;coll<=row;coll++)
{
Console.Write(temp);
temp += 2;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
1
2 4
1 3 5
2 4 6 8
1 3 5 7 9
class Program
{
static void Main(string[] args)
{
int temp=0;
Console.WriteLine("Enter the number");
int n = int.Parse(Console.ReadLine());
for(int row=0;row<=n;row++)
{
if(row%2==0)
{
temp = 2;
}
else
{
temp = 1;
}
for(int coll=1;coll<=row;coll++)
{
Console.Write(temp);
temp += 2;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
No comments:
Post a Comment