Hello geeks!
This article shows how to draw patterns in a C# console program, especially triangle patterns, like upward and downward.
Triangle: 1
This triangle is a simple triangle; we can draw that in several ways. I am showing two techniques of doing this using a simple for loop.
The first one will be like this:
- for (j = 1; j <= i; j++)
- {
- Console.Write("");
- }
- for (k = 1; k <= i; k++)
- for (j = 1; j <= val-i; j++)
- {
- // Console.Write("");
- }
- for (k = 1; k <= i; k++)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Hello_Word
- {
- class Program
- {
- static void Main(string[] args)
- {
- int val = 5;
- int i, j, k ;
- for (i = 1; i <= val; i++)
- {
- for (j = 1; j <= i; j++)
- {
- Console.Write("");
- }
- for (k = 1; k <= i; k++)
- {
- Console.Write("*");
- }
- Console.WriteLine("");
- }
- Console.ReadLine();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Hello_Word
- {
- class Program
- {
- static void Main(string[] args)
- {
- int val = 5;
- int i, j, k ;
- for (i = 1; i <= val; i++)
- {
- for (j = 1; j <= val-i; j++)
- {
- // Console.Write("");
- }
- for (k = 1; k <= i; k++)
- {
- Console.Write("*");
- }
- Console.WriteLine("");
- }
- Console.ReadLine();
- }
- }
- }

Triangle: 2
The triangle in this category is just the opposite of the first type of triangle patterns. There is no difficulty in applying loops for them, what we need to do is to make some little changes in the for loop conditions and it will work fine.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Hello_Word
- {
- class Program
- {
- static void Main(string[] args)
- {
- int val = 5;
- int i, j, k ;
- for (i = 1; i <= val; i++)
- {
- for (j = 1; j <= val-i; j++)
- {
- Console.Write(" ");
- }
- for (k = 1; k <= i; k++)
- {
- Console.Write("*");
- }
- Console.WriteLine("");
- }
- Console.ReadLine();
- }
- }
- }
Output Window

Triangle: 3
In this category we just get a mirror triangle of the first triangle pattern. You can also make changes in the second category to get a mirror triangle pattern of that.
But the following is the code for only the first cat of triangle mirror.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Hello_Word
- {
- class Program
- {
- static void Main(string[] args)
- {
- int val = 5;
- int i, j, k ;
- for (i = 1; i <= val; i++)
- {
- for (j = 1; j <= val-i; j++)
- {
- // Console.Write(" ");
- }
- for (k = 1; k <= j; k++)
- {
- Console.Write("*");
- }
- Console.WriteLine("");
- }
- Console.ReadLine();
- }
- }
- }


Nika BitsadzePosted Apr 27, 2021, 8:11 AM
Thanks for the unnecessary "For" loop in the first example, I was able to figure out lazy students
Mohau NtholengPosted Jul 7, 2020, 7:48 AM
Hi Sir I wanted to ask how do you draw a x using these stars
Arun KumarPosted Mar 18, 2019, 10:41 AM
Sir , can u say me how to became a successfull programmer
Raahim KhanPosted Sep 1, 2018, 12:54 AM
Saad hussain, here is the same book in pdf. Go through it so that you will be able to build your basic concepts. :)https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=2ahUKEwiRitjGlpndAhUFaBoKHdUqCwEQFjAAegQIBRAC&url=https%3A%2F%2Fwww.cluster2.hostgator.co.in%2Ffiles%2Fwriteable%2Fuploads%2Fhostgator99706%2Ffile%2Fletusc-yashwantkanetkar.pdf&usg=AOvVaw1m_5ANeEYUEuY6SN88CkSK
Raahim KhanPosted Sep 1, 2018, 12:50 AM
Saad hussain, this book is a good guide for beginners.
Raahim KhanPosted Sep 1, 2018, 12:49 AM
Saad hussain, you can have "Let Us C," by Yashavant Kanetkar.
satish gunturiPosted Aug 3, 2018, 9:53 PM
For (int i = 0; i < 5; i++) { console.writeline(""); { for (int j = 0; j <= i; j++) { console.writel("*"); } } } console.readkey(); { for (int j = 0; j <= i; j++) { console.writel("*"); } } } console.readkey();
Shahbaz KhanPosted May 13, 2018, 10:30 PM
AOA, I need to print like Alphabet A in stars how its possible...
Kselva KumarPosted Aug 4, 2017, 5:18 AM
May be this one is easy
Kselva KumarPosted Aug 4, 2017, 5:17 AM
Http://www.c-sharpcorner.com/Blogs/triangle-in-c-sharp-a-simplest-way-to-do
GokulPosted May 28, 2016, 8:03 AM
c# bigginners wiil help this program
Abhishek JaiswalPosted Dec 18, 2014, 8:24 AM
what kinda solution u want aditya?
Abhishek JaiswalPosted Dec 18, 2014, 8:24 AM
you can also download this e-book, http://www.c-sharpcorner.com/ebooks/free/53/programming-C-Sharp-for-beginners.aspx
Abhishek JaiswalPosted Dec 18, 2014, 8:23 AM
saad hussain, for basics you can go through balagurusamy and for detail Black Book!
saad hussainPosted Oct 27, 2014, 11:13 AM
i mean practice book
saad hussainPosted Oct 27, 2014, 11:12 AM
Please tell me some book on C#
Abhishek JaiswalPosted Apr 15, 2014, 6:38 AM
yeah u must, i'll try to update it.
Abhishek JaiswalPosted Apr 9, 2014, 4:27 AM
please, stop this nonsense!