Program to Print K using Alphabets

Given a number n, the task is to print ‘K’ using alphabets.

Examples:

Input: n = 5
Output: 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 

Input: n = 3
Output:
A B C D 
A B C 
A B 
A 
A 
A B 
A B C 
A B C D 

Below is the implementation.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python Program to design the 
# above pattern of K using alphabets
   
# Function to print the above Pattern
def display(n):
    v = n
      
    # This loop is used for rows and 
    # prints the alphabets in decreasing
    # order
    while ( v >= 0) : 
        c = 65
          
        # This loop is used for columns
        for j in range(v + 1): 
              
            # chr() function converts the 
            # number to alphabet
            print( chr ( c + j ), end = " "
        v = v - 1
        print()
          
    # This loop is again used to rows and
    # prints the half remaining pattern in
    # increasing order
    for i in range(n + 1): 
        c = 65
          
        for j in range( i + 1):
            print( chr ( c + j), end =" ")
        print()
  
# Driver code
n = 5
display(n)

chevron_right


Output:

A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.