Monday, September 17, 2018

Csharp program to print a Rhombus:

for (int i = 1; i <= 5; i++)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
            for (int i = 4; i > 0; i--)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

output : 

1
212
32123
4321234
32123
212
1

No comments:

Post a Comment