C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Write A Program To Show Pyramidal Structure In C#
WhatsApp
Anil Jha
8y
11.9
k
0
2
25
Blog
Introduction
In this blog, I am going to discuss how to show pyramid by using loop in C#.
Algorithm
Get no. of rows that can be shown in pyramid.
Loop through no. of rows.
Find the centre point and add star(*).
Add 2 * more than previous row in every row.
Code:
class
Program
{
static
void
Main(
string
[] args)
{
int
rows = 15;
for
(
int
i = 0; i < rows; i++)
{
for
(
int
j = rows -i - 1; j > 0; j--)
{
Console.Write(
" "
);
}
for
(
int
k = 0; k < (i +1)* 2 - 1; k++)
{
Console.Write(
"*"
);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
Output
People also reading
Membership not found