C# Program to Print Right Triangle, Half Pyramid Pattern

Right Triangle, Pyramid Pattern

C# programs to print the half pyramid pattern have been given here. Both the right half and left half of the pyramid using *, numbers and letters have been covered.






1. Program & output to print the right half pyramid pattern




1.1. C# Program & output to print the right half pyramid pattern using *

Code has been copied
/*****************************
  	alphabetacoder.com
C# Program to print the right
half pyramid pattern using *
******************************/

using System;

namespace RightHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print *
                for (j = 1; j <= i; j++) {
                    Console.Write("*");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


*

**

***

****

*****

******




1.2. C# Program & output to print the right half pyramid pattern using numbers

Code has been copied
/*********************************
  	alphabetacoder.com
C# Program to print the right
half pyramid pattern using numbers
**********************************/

using System;

namespace RightHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print numbers
                for (j = 1; j <= i; j++) {
                    Console.Write(j + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6




1.3. C# Program & output to print the right half pyramid pattern using alphabets

Code has been copied
/***********************************
       alphabetacoder.com
C# Program to print the right
half pyramid pattern using alphabets
************************************/

using System;

namespace RightHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print letters
                for (j = 1; j <= i; j++) {
                    Console.Write((char)(j + 64) + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


A

A B

A B C

A B C D

A B C D E

A B C D E F




2. Program & output to print the left half pyramid pattern




2.1. C# Program & output to print the left half pyramid pattern using *

Code has been copied
/********************************
    alphabetacoder.com
C# Program to print the left half
of the pyramid pattern using *
*********************************/

using System;

namespace LeftHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print space
                for (j = 1; j <= row - i; j++) {
                    Console.Write(" ");
                }
                // print *
                for (j = 1; j <= i; j++) {
                    Console.Write("*");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


     *

    **

   ***

  ****

 *****

******




2.2. C# Program & output to print the left half pyramid pattern using numbers

Code has been copied
/***********************************
    	alphabetacoder.com
C# Program to print the left half
of the pyramid pattern using numbers
************************************/

using System;

namespace LeftHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print space
                for (j = 1; j <= 2 * (row - i); j++) {
                    Console.Write(" ");
                }
                // print numbers
                for (j = 1; j <= i; j++) {
                    Console.Write(j + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 5


        1

      1 2

    1 2 3

  1 2 3 4

1 2 3 4 5




2.3. C# Program & output to print the left half pyramid pattern using alphabets

Code has been copied
/*************************************
    	alphabetacoder.com
C# Program to print the left half
of the pyramid pattern using alphabets
**************************************/

using System;

namespace LeftHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print space
                for (j = 1; j <= 2 * (row - i); j++) {
                    Console.Write(" ");
                }
                // print letters
                for (j = 1; j <= i; j++) {
                    Console.Write((char)(j + 64) + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 5


        A

      A B

    A B C

  A B C D

A B C D E




3. Program & output to print the right half pyramid pattern




3.1. C# Program & output to print the inverted half pyramid pattern using *

Code has been copied
/******************************
  	alphabetacoder.com
C# Program to print the inverted
half pyramid pattern using *
*******************************/

using System;

namespace InvertedHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print *
                for (j = row; j >= i; j--) {
                    Console.Write("*");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


******

*****

****

***

**

*




3.2. C# Program & output to print the inverted half pyramid pattern using numbers

Code has been copied
/*********************************
  	alphabetacoder.com
C# Program to print the inverted
half pyramid pattern using numbers
**********************************/

using System;

namespace InvertedHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print numbers
                for (j = row; j >= i; j--) {
                    Console.Write((row - j + 1) + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


1 2 3 4 5 6

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1




3.3. C# Program & output to print the inverted half pyramid pattern using alphabets

Code has been copied
/***********************************
  	alphabetacoder.com
C# Program to print the inverted
half pyramid pattern using alphabets
************************************/

using System;

namespace InvertedHalfPyramid {
    class Program {
        static void Main(string[] args) {
            // declare variables
            int row, i, j;

            // take input
            Console.Write("Enter the number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            // new line
            Console.WriteLine("");

            // display the pattern
            for (i = 1; i <= row; i++) {
                // print letters
                for (j = row; j >= i; j--) {
                    Console.Write((char)(row - j + 65) + " ");
                }
                // new line
                Console.WriteLine("");
            }
        }
    }
}

Output


Enter the number of rows: 6


A B C D E F

A B C D E

A B C D

A B C

A B

A