Login Register Appointment

Left Aligned Decreasing (*) Triangle Pattern

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

Pattern:


****

***

**

*


Solution

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


Pattern Breakdown

The total number of rows is 4.

The number of stars (*) in each row decreases as we move downward:

  1. Row 1 → 4
  2. Row 2 → 3
  3. Row 3 → 2
  4. Row 4 → 1


The outer loop runs from 0 to total_rows - 1.

The inner loop prints stars, starting from total_rows - row stars in each row.


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 decreasing stars)

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

                System.out.print("*");

            }

            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 decreasing stars)

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

            cout << "*";

        }

        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 decreasing stars)

    for col in range(total_rows - row):

        print("*", end="")

    print()  # Move to the next line