Star Series and Patterns Programs in C#
Half, Full, Incremented and Decrement Stars Series, Pyramid Pattern programs
Program 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = 0; i < MAX; i++) { for (j = 0; j <= i; j++) { Console.Write("*"); } Console.Write("\n"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | * ** *** **** ***** ****** ******* ******** ********* ********** |
Program 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = MAX; i >= 0; i--) { for (j = 0; j <= i; j++) { Console.Write("*"); } Console.Write("\n"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 | *********** ********** ********* ******** ******* ****** ***** **** *** ** * |
Program 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | static void Main(string[] args) { int i, j; int space = 10; int MAX = space; for (i = 0; i < MAX; i++) { for (j = 0; j < space; j++) { Console.Write(" "); } for (j = 0; j <= i; j++) { Console.Write("* "); } Console.Write("\n"); space--; } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
Program 4:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | static void Main(string[] args) { int i, j; int space = 10; int MAX = space+1; for (i = 0; i < MAX; i++) { for (j = 0; j < space; j++) { Console.Write(" "); } for (j = 0; j <= i; j++) { Console.Write("* "); } Console.Write("\n"); space--; } space = 0; for (i = MAX; i > 0; i--) { for (j = 0; j < space; j++) { Console.Write(" "); } for (j = 0; j < i; j++) { Console.Write("* "); } Console.Write("\n"); space++; } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
Program 5:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | static void Main(string[] args) { int i, j; int space = 0; int MAX = 10; for (i = MAX; i > 0; i--) { for (j = 0; j < i; j++) { Console.Write("*"); } for (j = 0; j < space; j++) { Console.Write(" "); } for (j = 0; j < i; j++) { Console.Write("*"); } Console.Write("\n"); space += 2; } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | ******************** ********* ********* ******** ******** ******* ******* ****** ****** ***** ***** **** **** *** *** ** ** * * |
Program 6:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | static void Main(string[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= 5; j++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 | ***** ***** ***** ***** ***** |
Program 7:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = 1; j <= i; j++) { if (j == 1 || j == i || i == MAX) { Console.Write("*"); } else { Console.Write(" "); } } Console.WriteLine(); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | * ** * * * * * * * * * * * * * * ********** |
Program 8:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = i; j < MAX; j++) { Console.Write(" "); } for (j = 1; j <= i; j++) { if (i == MAX || j == 1 || j == i) { Console.Write("*"); } else { Console.Write(" "); } } Console.WriteLine(); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | * ** * * * * * * * * * * * * * * ********** |
Program 9:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); } for (i = MAX; i >= 1; i--) { for (j = 1; j < i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | * ** *** **** ***** ****** ******* ******** ********* ********** ********* ******** ******* ****** ***** **** *** ** * |
Program 10:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | static void Main(string[] args) { int i, j, k; int MAX = 10; for (i = 0; i <= MAX; i++) { for (j = MAX; j > i; j--) Console.Write(" "); for (k = 0; k <= i; k++) { if (k % 2 == 0) Console.Write("0"); else Console.Write("1"); } Console.Write("\n"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 | 0 01 010 0101 01010 010101 0101010 01010101 010101010 0101010101 01010101010 |
Program 11:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | static void Main(string[] args) { int i, j, k, l = 1; int space = 5; int MAX = space; for (i = 1; i <= MAX; i++) { for (j = space; j >= i; j--) { Console.Write(" "); } for (k = 1; k <= l; k++) { Console.Write(k); } l = l + 2; Console.Write("\n"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 | 1 123 12345 1234567 123456789 |
Program 12:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | static void Main(string[] args) { int i, j; char ch = 'A'; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = 1; j <= i; j++) { Console.Write(ch++); } Console.Write("\n"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | A BC DEF GHIJ KLMNO PQRSTU VWXYZ[\ ]^_`abcd efghijklm nopqrstuvw |
Program 13:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | static void Main(string[] args) { int i, j; int space = 10; int MAX = space; for (i = 1; i <= MAX; i++) { for (j = MAX; j > i; j--) { Console.Write(" "); } Console.Write("*"); for (j = 1; j < (i - 1) * 2; j++) { Console.Write(" "); } if (i == 1) Console.WriteLine(); else Console.WriteLine("*"); } for (i = space; i >= 1; i--) { for (j = MAX; j > i; j--) { Console.Write(" "); } Console.Write("*"); for (j = 1; j < (i - 1) * 2; j++) { Console.Write(" "); } if (i == 1) Console.WriteLine(); else Console.WriteLine("*"); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
Program 14:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | static void Main(string[] args) { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = i; j < MAX; j++) { Console.Write(" "); } for (j = 1; j <= (2 * i - 1); j++) { if (i == MAX || j == 1 || j == (2 * i - 1)) { Console.Write("*"); } else { Console.Write(" "); } } Console.WriteLine(); } Console.ReadLine(); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | * * * * * * * * * * * * * * * * * ******************* |