Home / Programs / C# Program to Print Alphabet Triangle
Programming Example

C# Program to Print Alphabet Triangle

👁 633 Views
💻 Practical Program
📘 Step by Step Learning

There are different triangles that can be printed. Triangles can be generated by alphabets or numbers. In this C# program, we are going to print alphabet triangles.

Let's see the C# example to print alphabet triangle.

Program Code

using System;  
  public class PrintExample  
   {  
     public static void Main(string[] args)  
      {  
       char ch='A';      
       int i, j, k, m;      
       for(i=1; i<=5; i++)      
       {      
        for(j=5; j>=i; j--)      
         Console.Write(" ");      
        for(k=1;k<=i;k++)      
         Console.Write(ch++);      
        ch--;      
        for(m=1;m<i;m++)      
         Console.Write(--ch);      
        Console.Write("\n");      
        ch='A';      
       }      
   }  
  }  

Output

     A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.