*
***
*****
*******
Updated
As you can see below the code for simple pyramid has two for loop nested in each other.
So for each row it enter, it increment the counter and draw the star against forming a pyramid like figure. You can use different special counter, play with the loop and enjoy the coding.
Simple Pyramid in Csharp
class Program
{
static void Main(string[] args)
{
int row, col = 0, n = 5;
for (row = 0; row <= n; row++)
{
for (int r = 0; r <= row; r++)
{
Console.Write(" ");
}
for (col = 1; col <= 2 * row - 1; col++)
{
Console.Write("*");
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
Output:
Original posted on 01 March 2013
***
*****
*******
Updated
As you can see below the code for simple pyramid has two for loop nested in each other.
So for each row it enter, it increment the counter and draw the star against forming a pyramid like figure. You can use different special counter, play with the loop and enjoy the coding.
Simple Pyramid in Csharp
class Program
{
static void Main(string[] args)
{
int row, col = 0, n = 5;
for (row = 0; row <= n; row++)
{
for (int r = 0; r <= row; r++)
{
Console.Write(" ");
}
for (col = 1; col <= 2 * row - 1; col++)
{
Console.Write("*");
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
Output:
Original posted on 01 March 2013
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.