C# program to print below star diamond by entering no of lines
*
***
*****
*******
*****
***
*
Here's the C# program that prints the diamond pattern based on the number of lines entered by the user:
using System;
class Program
{
static void Main()
{
Console.Write("Enter the number of lines: ");
int numLines = Convert.ToInt32(Console.ReadLine());
// Upper part of the diamond
for (int i = 1; i <= numLines; i++)
{
// Print spaces
for (int j = 1; j <= numLines - i; j++)
{
Console.Write(" ");
}
// Print stars
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
// Lower part of the diamond
for (int i = numLines - 1; i >= 1; i--)
{
// Print spaces
for (int j = 1; j <= numLines - i; j++)
{
Console.Write(" ");
}
// Print stars
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
This program prompts the user to enter the number of lines, then it uses nested loops to print the diamond pattern. The upper part of the diamond is printed first, followed by the lower part. The logic for printing spaces and stars remains the same as in the previous program.