C Sharp Program to Print Alphabet Triangle

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

C# Program to Print Alphabet Triangle

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.

 
  1. using System;  
  2.   public class PrintExample  
  3.    {  
  4.      public static void Main(string[] args)  
  5.       {  
  6.        char ch='A';      
  7.        int i, j, k, m;      
  8.        for(i=1; i<=5; i++)      
  9.        {      
  10.         for(j=5; j>=i; j--)      
  11.          Console.Write(" ");      
  12.         for(k=1;k<=i;k++)      
  13.          Console.Write(ch++);      
  14.         ch--;      
  15.         for(m=1;m
  16.          Console.Write(--ch);      
  17.         Console.Write(" ");      
  18.         ch='A';      
  19.        }      
  20.    }  
  21.   }  

Output:

     A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA