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, 4:11 AM EDT
Thanks for the unnecessary "For" loop in the first example, I was able to figure out lazy students
Mohau NtholengPosted Jul 7, 2020, 3:48 AM EDT
Hi Sir I wanted to ask how do you draw a x using these stars
Arun KumarPosted Mar 18, 2019, 6:41 AM EDT
Sir , can u say me how to became a successfull programmer
Raahim KhanPosted Aug 31, 2018, 8:54 PM EDT
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 Aug 31, 2018, 8:50 PM EDT
Saad hussain, this book is a good guide for beginners.
Raahim KhanPosted Aug 31, 2018, 8:49 PM EDT
Saad hussain, you can have "Let Us C," by Yashavant Kanetkar.
satish gunturiPosted Aug 3, 2018, 5:53 PM EDT
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, 6:30 PM EDT
AOA, I need to print like Alphabet A in stars how its possible...
Kselva KumarPosted Aug 4, 2017, 1:18 AM EDT
May be this one is easy
Kselva KumarPosted Aug 4, 2017, 1:17 AM EDT
Http://www.c-sharpcorner.com/Blogs/triangle-in-c-sharp-a-simplest-way-to-do
GokulPosted May 28, 2016, 4:03 AM EDT
c# bigginners wiil help this program
Abhishek JaiswalPosted Dec 18, 2014, 3:24 AM EST
what kinda solution u want aditya?
Abhishek JaiswalPosted Dec 18, 2014, 3:24 AM EST
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, 3:23 AM EST
saad hussain, for basics you can go through balagurusamy and for detail Black Book!
saad hussainPosted Oct 27, 2014, 7:13 AM EDT
i mean practice book
saad hussainPosted Oct 27, 2014, 7:12 AM EDT
Please tell me some book on C#
Abhishek JaiswalPosted Apr 15, 2014, 2:38 AM EDT
yeah u must, i'll try to update it.
Abhishek JaiswalPosted Apr 9, 2014, 12:27 AM EDT
please, stop this nonsense!