Enter the number: 5
1 2 3 4 5 4 3 2 1
1 2 3 4 * 4 3 2 1
1 2 3 * * * 3 2 1
1 2 * * * * * 2 1
1 * * * * * * * 1
class Program
1 2 3 4 5 4 3 2 1
1 2 3 4 * 4 3 2 1
1 2 3 * * * 3 2 1
1 2 * * * * * 2 1
1 * * * * * * * 1
class Program
{
static void Main(string[] args)
{
int ro, cl, sp, tp, no;
Console.WriteLine("enter your no of rows to print ");
no = int.Parse(Console.ReadLine());
tp = no;
for (ro = 0; ro < no; ro++)
{
for (cl = 1; cl <= no - ro; cl++)
{
Console.Write(cl);
}
for (sp = 1; sp < (ro * 2); sp++)
{
Console.Write("*");
}
for (cl = cl - 1; cl > 0; cl--)
{
if (cl < no)
Console.Write(cl);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
No comments:
Post a Comment