Program for triangular patterns of alphabets

28 Jun, 2022
Pattern printing has always been an interesting topic in programming languages. It emphasizes the usage of inner and outer loops in nested loops and creates beautiful patterns from them. Below are given some patterns using alphabets. Our task is to write programs for the below-given patterns, such that each pattern should print on the basis of given input ‘n’ when n = count of alphabets.
First Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
// C++ code for triangular// patterns of alphabets#include <bits/stdc++.h>using namespace std; int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++)    {        for (j = i; j <= n; j++)        {            cout << (char)('A' - 1 + j) << " ";        }        cout << endl;    }    return 0;} // This code is contributed by// shubhamsingh10
#include <stdio.h>int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = i; j <= n; j++) {            printf("%c", 'A' - 1 + j);        }        printf("\n");    }    return 0;}
class GFG{public static void main(String args[]){    int i, j, n = 5;    for (i = 1; i <= n; i++)    {        int ch = 65;            for (j = i; j <= n; j++)            {                System.out.print((char)(ch -1 + j) + " ");            }        System.out.print("\n");    }}} // This code is contributed// by Akanksha Rai
# Python 3 code for triangular# patterns of alphabetsn = 5for i in range(1, n + 1):    for j in range(i, n + 1):        print(chr(ord('A') - 1 + j), end = ' ')    print() # This code is contributed# by SamyuktaSHegde
using System;class GFG{public static void Main(){    int i, j, n = 5;    for (i = 1; i <= n; i++)    {        int ch = 65;            for (j = i; j <= n; j++)            {                Console.Write((char)(ch - 1 + j) + " ");            }        Console.Write("\n");    }}} // This code is contributed// by Akanksha Rai
<?php// PHP code for triangular// patterns of alphabets $n = 5;    for ($i = 1; $i <= $n; $i++)    {        for ($j = $i; $j <= $n; $j++)        {            echo chr(65 - 1 + $j)." ";        }        echo "\n";    } // This code is contributed by mits?>
<script>       // JavaScript code for triangular      // patterns of alphabets      var i,        j,        n = 5;      for (i = 1; i <= n; i++)      {        for (j = i; j <= n; j++)        {          document.write(            String.fromCharCode("A".charCodeAt(0) - 1 + j)            + "  "          );        }        document.write("<br>");      }       </script>
Output:  
A B C D E 
B C D E
C D E
D E
E
Second Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
#include <bits/stdc++.h>using namespace std;int main(){    int i, j, n = 5;    for (i = n; i >= 1; i--) {        for (j = 1; j <= i; j++) {            cout << (char)('A' - 1 + i) << " ";        }        cout << endl;    }    return 0;} // This code is contributed by shubhamsingh10
#include <stdio.h>int main(){    int i, j, n = 5;    for (i = n; i >= 1; i--) {        for (j = 1; j <= i; j++) {            printf("%c ", 'A' - 1 + i);        }        printf("\n");    }    return 0;}
class GFG{     // Driver codepublic static void main(String[] args){    int i, j, n = 5;    for (i = n; i >= 1; i--)    {        for (j = 1; j <= i; j++)        {            System.out.printf("%c ", 'A' - 1 + i);        }        System.out.printf("\n");    }    }} // This code is contributed by PrinciRaj1992
# Python3 code for triangular# patterns of alphabetsn = 5for i in range(n, 0, -1):    for j in range(1, i + 1, 1):        print(chr(ord('A') - 1 + i),                            end = ' ')    print() # This code is contributed by Rajput-Ji
// C# code for triangular// patterns of alphabetsusing System;     class GFG{     // Driver codepublic static void Main(String[] args){    int i, j, n = 5;    for (i = n; i >= 1; i--)    {        for (j = 1; j <= i; j++)        {            Console.Write("{0} ",                         (char)('A' - 1 + i));        }        Console.Write("\n");    }}} // This code is contributed// by Princi Singh
<?php// PHP code for triangular// patterns of alphabets $n = 5;    for ($i = $n; $i >= 1; $i--)    {        for ($j = 1; $j <= $i; $j++)        {            echo chr(65 - 1 + $i)." ";        }        echo "\n";    } // This code is contributed by mits?>
<script> var i, j, n = 5; for (i = n; i >= 1; i--){    for (j = 1; j <= i; j++)    {        document.write(String.fromCharCode('A'.charCodeAt(0) - 1 + i)        +" ");    }    document.write("<br>");} // This code is contributed by 29AjayKumar </script>
Output:  
E E E E E
D D D D
C C C
B B
A
Third Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
#include <iostream>using namespace std;int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = 1; j <= i; j++) {            cout << (char)('A' + j - 1) << " ";        }        cout << endl;    }    return 0;} // This code is contributed by shubhamsingh10
#include <stdio.h>int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = 1; j <= i; j++) {            printf("%c ", 'A' + j - 1);        }        printf("\n");    }    return 0;}
import java.io.*; class GFG{    public static void main (String[] args)    {        int i, j, n = 5;        for (i = 1; i <= n; i++)        {            int ch = 65;            for (j = 1; j <= i; j++)            {                System.out.print(((char)ch));                ch++;            }        System.out.println();        }    }} //This code is contributed by m_kit
# Python3 code for triangular# patterns of alphabetsif __name__ == '__main__':         n = 5;    for i in range(1, n + 1):        for j in range(1, i + 1):            print(chr(ord('A') + j - 1),                             end = " ");         print("");     # This code is contributed by 29AjayKumar
// C# code for triangular// patterns of alphabetsusing System; class GFG{    static public void Main ()    {                 int i, j, n = 5;        for (i = 1; i <= n; i++)        {            int ch = 65;            for (j = 1; j <= i; j++)            {                Console.Write(((char)ch));                ch++;            }        Console.WriteLine();        }    }} // This code is contributed by ajit
<?php// PHP code for triangular// patterns of alphabets $n = 5;    for ($i = 1; $i <= $n; $i++)    {        for ($j = 1; $j <= $i; $j++)        {                         //Ascii value of A is 65            echo chr(65 + $j - 1)." ";        }        echo "\n";    } // This code is contributed by mits?>
<script> let i, j, n = 5;for(i = 1; i <= n; i++){    let ch = 65;    for(j = 1; j <= i; j++)    {        document.write(            String.fromCharCode(ch) + " ");        ch++;    }    document.write("<br>");} // This code is contributed by rag2127 </script>
Output:  
A
A B
A B C
A B C D 
A B C D E
Fourth Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
#include <iostream>using namespace std; int main(){    int i, j, n = 5;    for (i = n; i >= 1; i--) {        for (j = i; j <= n; j++) {            cout << (char)('A' + j - 1) << " ";        }        cout << endl;    }    return 0;} // This code is contributed by Shubhamsingh10
#include <stdio.h>int main(){    int i, j, n = 5;    for (i = n; i >= 1; i--) {        for (j = i; j <= n; j++) {            printf("%c ", 'A' + j - 1);        }        printf("\n");    }    return 0;}
// Java code for triangular// patterns of alphabetsclass GFG{    public static void main(String[] args)    {        int i, j, n = 5;        for (i = n; i >= 1; i--)        {            for (j = i; j <= n; j++)            {                System.out.printf("%c ", ('A' + j - 1));            }            System.out.println("");        }    }} // This code is contributed by PrinciRaj1992
# Python3 code for triangular# patterns of alphabetsif __name__ == '__main__':    n = 5;    for i in range(n, 0, -1):        for j in range(i, n + 1, 1):            print(chr(ord('A') + j - 1),                             end = " ");         print(""); # This code is contributed by Rajput-Ji
// C# code for triangular// patterns of alphabetsusing System; class GFG{    public static void Main()    {        int i, j, n = 5;        for (i = n; i >= 1; i--)        {            for (j = i; j <= n; j++)            {                Console.Write("{0} ",(char)('A' + j - 1));            }            Console.WriteLine("");        }    }} // This code is contributed by Code_Mech
<?php// PHP code for triangular// patterns of alphabets $n = 5;for ($i = $n; $i >= 1; $i--){    for ($j = $i; $j <= $n; $j++)    {        echo chr(65 + $j - 1)." ";    }    echo "\n";} // This code is contributed by mits?>
<script> let i, j, n = 5;        for (i = n; i >= 1; i--)        {            for (j = i; j <= n; j++)            {                document.write(String.fromCharCode('A'.charCodeAt(0) + j - 1)+" ");            }            document.write("<br>");        }  // This code is contributed by avanitrachhadiya2155</script>
Output:  
E
D E
C D E
B C D E
A B C D E
Fifth Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
#include <iostream>using namespace std;int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = n; j >= i; j--) {            cout <<(char)('A' - 1 + i)<<" ";        }        cout << endl;    }    return 0;} // This code is contributed by shubhamsingh10
#include <stdio.h>int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = n; j >= i; j--) {            printf("%c ", 'A' - 1 + i);        }        printf("\n");    }    return 0;}
/* Java program to find bestmeeting point in 2D array*/import java.util.*; public class GFG{ public static void main(String[] args){    int i, j, n = 5;    for (i = 1; i <= n; i++)    {        for (j = n; j >= i; j--)        {            System.out.printf("%c ", ('A' - 1 + i));        }        System.out.println("");;    }}} // This code is contributed by 29AjayKumar
# Python3 code for triangular# patterns of alphabetsif __name__ == '__main__':    i, j, n = 0, 0, 5;    for i in range(1, n + 1):        for j in range(n, i - 1, -1):            print(chr(ord('A') - 1 + i), end = " ");        print(""); # This code is contributed by Princi Singh
/* C# program to find bestmeeting point in 2D array*/using System; class GFG{ // Driver codepublic static void Main(String[] args){    int i, j, n = 5;    for (i = 1; i <= n; i++)    {        for (j = n; j >= i; j--)        {            Console.Write("{0} ", (char)('A' - 1 + i));        }        Console.WriteLine("");;    }}} // This code contributed by Rajput-Ji
<?php// PHP code for triangular// patterns of alphabets $n = 5;    for ($i = 1; $i <= $n; $i++)    {        for ($j = $n; $j >= $i; $j--)        {            echo chr(65 - 1 + $i)." ";        }        echo "\n";    } // This code is contributed by mits?>
<script>  /* JavaScript program to find bestmeeting point in 2D array*/var i, j, n = 5;    for (i = 1; i <= n; i++)    {        for (j = n; j >= i; j--)        {              document.write(String.fromCharCode('A'.charCodeAt(0) - 1 + i)+" ");        }        document.write("<br>");    } // This code is contributed by shivanisinghss2110 </script>
Output:  
A A A A A
B B B B
C C C 
D D 
E
Sixth Pattern : 
C++
C
Java
Python3
C#
PHP
Javascript
// C++ code for triangular// patterns of alphabets#include <iostream>using namespace std; int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = i; j >= 1; j--) {            cout << (char)('A' + j - 1) << " ";        }        cout << endl;    }    return 0;} // This code is contributed by SHUBHAMSINGH10
// C code for triangular// patterns of alphabets#include <stdio.h>int main(){    int i, j, n = 5;    for (i = 1; i <= n; i++) {        for (j = i; j >= 1; j--) {            printf("%c ", 'A' + j - 1);        }        printf("\n");    }    return 0;}
// Java code for triangular// patterns of alphabetsclass GFG{     public static void main(String[] args)    {        int i, j, n = 5;        for (i = 1; i <= n; i++)        {            for (j = i; j >= 1; j--)            {                System.out.printf("%c ", 'A' + j - 1);            }            System.out.printf("\n");        }    }} // This code is contributed by Rajput-Ji
# Python3 code for triangular# patterns of alphabets if __name__ == '__main__':         i, j, n = 0, 0, 5;    for i in range(1, n + 1):        for j in range(i, 0, -1):            print(chr(ord('A') + j - 1),                             end = " ");         print(); # This code is contributed by Rajput-Ji
// C# code for triangular// patterns of alphabetsusing System; class GFG{     // Driver code    public static void Main(String[] args)    {        int i, j, n = 5;        for (i = 1; i <= n; i++)        {            for (j = i; j >= 1; j--)            {                Console.Write("{0} ",                    Convert.ToChar('A' + j - 1));            }            Console.Write("\n");        }    }} // This code is contributed by PrinciRaj1992
<?php// PHP code for triangular// patterns of alphabets $n = 5;for ($i = 1; $i <= $n; $i++){    for ($j = $i; $j >= 1; $j--)    {        echo chr(65 + $j - 1)." ";    }    echo "\n";} // This code is contributed by mits?>
Javascript<script>  /* JavaScript program to find bestmeeting point in 2D array*/var i, j, n = 5;    for (i = 1; i <= n; i++)        {            for (j = i; j >= 1; j--)        {               document.write(String.fromCharCode('A'.charCodeAt(0) + j - 1)+" ");        }        document.write("<br>");    } // This code is contributed by shivanisinghss2110 </script>
Output:  
A 
B A
C B A
D C B A
E D C B A
 Time complexity: O(n*n)
Auxiliary Space: O(1)
Mithun Kumar
jit_t
SamyuktaSHegde
Akanksha_Rai
Rajput-Ji
princiraj1992
29AjayKumar
Code_Mech
princi singh
SHUBHAMSINGH10
rdtank
shikhasingrajput
rag2127
avanitrachhadiya2155
shivanisinghss2110
krishnav4
pattern-printing
C Programs
School Programming
pattern-printing
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.