-> Write a program of diamond pattern is using with three loops?
class Program
{ static void Main(string[] args)
{
int val=0;
int temp=0;
Console.WriteLine("Enter the input number");
int n = int.Parse(Console.ReadLine());
for (int row = 0; row < (2 * n - 1); row++)
if (row <= (n - 1))
{ for(int space=0;space<n+row;space++)
if (space< (n - row) - 1)
{
Console.Write(" ");
}
else
{
Console.Write("*");
} Console.WriteLine();
}
else
{
temp += 2;
val++;
for (int coll = 0; coll < (row+n)-temp; coll++)
if (coll < val)
{
Console.Write(" ");
}
else
{
Console.Write("*");
} Console.WriteLine();
} Console.WriteLine();
Console.ReadLine();
}
} OUTPUT:
No comments:
Post a Comment