This article helps to create a star pattern in the C# console application (Part -2).
6.
1
21
321
4321
54321
static void Main(string[] args) { int i, j, n ; string data; Console.Write("enter a number"); data = Console.ReadLine(); n = Convert.ToInt16(data); for (i = 1; i <=n; i++) { for (j = n; j >= 1; j--) { if (i == j) { for (int k = i; k >= 1; k--) { Console.Write(k); } } else { Console.Write(" "); } } Console.WriteLine(); } Console.ReadLine(); }
7.
static void Main(string[] args) { int i,j, n = 5; int flag = 1; for (i = 1; i <=n ; i++) { flag = i; for (j= 1; j <= i; j++) { for (j = 1; j <= (n-i); j++) { Console.Write(" "); } for (j = flag; j <= flag +(i-1) ; j++) { Console.Write(j); } if (i != 1) { for (j = flag + (i-2); j >= flag; j--) { Console.Write(j); } } for (j = 1; j <= (n - i); j++) { Console.Write(" "); } //Console.WriteLine(); break; } Console.WriteLine(); } Console.ReadLine(); }
8.
54321
4321
321
21
1
static void Main(string[] args) { int i, j, n; string data; Console.Write("enter a number"); data = Console.ReadLine(); n = Convert.ToInt16(data); for (i = n; i >=1; i--) { for (j = n; j >= 1; j--) { if (i == j) { for (int k = i; k >= 1; k--) { Console.Write(k); } } else { Console.Write(" "); } } Console.WriteLine(); } Console.ReadLine(); }
9.
static void Main(string[] args) { int i, n,j; string data; Console.Write("enter a odd number"); data = Console.ReadLine(); n = Convert.ToInt16(data); int no = 0; decimal value = Convert.ToDecimal(n / 2); int midvalue = Convert.ToInt16(Math.Round(value)); if (n % 2 == 0) { Console.WriteLine("please enter odd number"); Console.ReadLine(); } else { for (i = midvalue; i > 1; i--) { if (i == midvalue) { for (j = 1; j <= n; j++) { Console.Write("*"); } Console.WriteLine(); } for (j = 1; j <= i; j++) { Console.Write("*"); } for (j = (2*(i-1)); j <= (1*(n-3)); j++) { Console.Write(" "); } for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); } for (i = 1; i <= midvalue; i++) { for (j = 1; j <= i; j++) { Console.Write("*"); } for (j = (2 * (i - 1)); j <= (1 * (n - 3)); j++) { Console.Write(" "); } for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); if (i == midvalue) { for (j = 1; j <= n; j++) { Console.Write("*"); } } } Console.ReadLine(); } }
also more pattern in Part -1 Here