Login Register Appointment

Left-Aligned Decreasing (Alphabet) Pattern

Lesson 11/21 | Study Time: 15 Min
Course: Pattern Program

Pattern:


ABCD

ABC

AB

A


Solution

Note: Don't jump directly to the solution, try it out yourself first.


Pattern Breakdown

The total number of rows is 4.

The numbers in each row start from 'A' and decrease in count as we move downward:

  1. Row 1 → ABCD ( 4 characters) 
  2. Row 2 → ABC(3 characters)
  3. Row 3 → AB (2 characters)
  4. Row 4 → A (1 character)


The outer loop runs from 0 to total_rows - 1.

The inner loop prints characters starting from 'A' up to total_rows - row characters.

Video Solution


Java


public class Main {

    public static void main(String[] args) {

        int total_rows = 4;  // Number of rows


        // Outer loop for rows (starting from 0)

        for (int row = 0; row < total_rows; row++) {

            // Inner loop for columns (printing letters)

            for (int col = 0; col < total_rows - row; col++) {

                System.out.print((char) ('A' + col));

            }

            System.out.println();  // Move to the next line

        }

    }

}



C++

#include <iostream>

using namespace std;

int main() {

    int total_rows = 4;  // Number of rows


    // Outer loop for rows (starting from 0)

    for (int row = 0; row < total_rows; row++) {

        // Inner loop for columns (printing letters)

        for (int col = 0; col < total_rows - row; col++) {

            cout << (char) ('A' + col);

        }

        cout << endl;  // Move to the next line

    }

    return 0;

}



Python


total_rows = 4  # Number of rows


# Outer loop for rows (starting from 0)

for row in range(total_rows):

    # Inner loop for columns (printing letters)

    for col in range(total_rows - row):

        print(chr(65 + col), end="")  # Convert 65 to 'A'

    print()  # Move to the next line