Different Star Pattern Programs in C#


Like any other programming languages such as C, C++, Java, we can easily display start pattern programs in C#.

star patterns

Let us see them one by one.

Example

 Live Demo

using System.IO;
using System;
class Program {
   static void Main() {
      for (int i = 1; i <= 6; ++i) {
         for (int j = 1; j <= i; ++j) {
            Console.Write("*");
         }
         Console.WriteLine();
      }
   }
}

Output

*
**
***
****
*****
******

Let us see another series.

Example

using System.IO;
using System;
class Program {
   static void Main() {
      int i, j, k;
      int n = 6,
      // loop to print the series
      for (i = 1; i <= n; i++) {
         for (j = 1; j <= n - i; j++) {
               Console.Write(" ");
         }
         for (k = 1; k <= i; k++) {
            Console.Write("*");
         }
         Console.WriteLine("");
      }
      Console.ReadLine();
   }
}

Output

*
**
***
****
*****
******

Let us see another series.

Example

using System.IO;
using System;
class Program {
   static void Main() {
      for (int i = 6; i >= 1; --i) {
         for (int j = 1; j >= i; ++j) {
            Console.Write("*");
         }
         Console.WriteLine();
      }
   }
}

Output

******
*****
****
***
**
*

Here is another series.

Example

 Live Demo

using System.IO;
using System;
class Demo {
   static void Main() {
      int a = 1, spaces, k = 6, i = 0, j = 0;
      spaces = k - 1;
      for(i=1; i<k*2; i++) {
         for(j=1; j<=spaces; j++) {
            Console.Write(" ");
         }
         for(j=1; j<a*2; j++) {
            Console.Write("*");
         }
         Console.WriteLine("");
         if(i < k) {
            spaces--;
            a++;
         } else {
            spaces++;
            a--;
         }
      }
   }
}

Output

*
***
*****
*******
*********
***********
*********
*******
*****
***
*

Updated on: 23-Jun-2020

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements