Basic Programming C# Examples

C# Program to display Alphabet pattern ‘M’ with an asterisk

The Program in C# Program to display Alphabet pattern ‘M’ with an asterisk is given below:

using System;

namespace AlphabetPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            int rows = 5;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    if (j == 0 || j == rows - 1 || i == j || i == rows - 1 - j)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

Output:


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

Pro-Tips💡

Here are the step by step execution of above program:

  1. The program starts by using the “System” namespace.
  2. The program defines a namespace called “AlphabetPattern”.
  3. The program defines a class called “Program”.
  4. The program defines the Main method, which is the entry point of the program.
  5. The program defines a variable called “rows” and assigns it a value of 5, which represents the number of rows in the pattern.
  6. The program uses a for loop to iterate through the rows.
  7. The program uses a nested for loop to iterate through the columns in each row.
  8. The program checks the value of j and i. If j is equal to 0 or j is equal to rows - 1 or i is equal to j or i is equal to rows - 1 - j, it prints an asterisk to the console. Otherwise, it prints a space to the console.
  9. The program adds a line break after each row is complete.
  10. The program waits for the user to press Enter before closing the console.
  11. The program ends by returning 0 from the Main method.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X