Playing with stars in C#
*******
*****
***
*
class Program
{
static void Main(string[] args)
{
int row, col = 0, n = 5;
int k = n;
for (row = 0; row <= n; row++)
{
for (int r = 0; r <= row; r++)
{
Console.Write(" ");
}
for (col = 1; col <= k + (k - 1); col++)
{
Console.Write("*");
}
k--;
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
Output:
*******
*****
***
*
class Program
{
static void Main(string[] args)
{
int row, col = 0, n = 5;
int k = n;
for (row = 0; row <= n; row++)
{
for (int r = 0; r <= row; r++)
{
Console.Write(" ");
}
for (col = 1; col <= k + (k - 1); col++)
{
Console.Write("*");
}
k--;
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
Output:
Comments
Post a Comment
Important - Make sure to click the Notify Me check-box below the comment to be notified of follow up comments and replies.