New: 203 pattern programs with tested code in C, C++, Java and Python Explore patterns

Mirrored Parallelogram Star Pattern

Read summary with AI tools

The mirrored parallelogram star pattern prints the same row of 2n stars on every row and moves each row one space to the right, so the block leans the other way from the parallelogram star pattern.

Quick answer: Each row prints i − 1 spaces followed by 2n stars. The star count never changes; the growing indent alone creates the slant, because every row starts one column further right than the row above. For n = 4 that is four rows of eight stars, and the last row starts after three spaces.

This program is part of the Star Patterns collection.

Table of contents8 sections
  1. Output
  2. How the mirrored parallelogram star pattern works
  3. Program in C
  4. Program in C++
  5. Program in Java
  6. Program in Python
  7. Time and space complexity
  8. Frequently asked questions

Mirrored Parallelogram Star Pattern output

Output (4 rows, 8 stars per row):

********
 ********
  ********
   ********
Mirrored Parallelogram Star Pattern layout diagram, row by row (4 rows, 8 stars per row)
How each row of the mirrored parallelogram star pattern is built (4 rows, 8 stars per row). Blue cells are printed characters; grey dots are spaces.

How the mirrored parallelogram star pattern works

This is one of the simplest shapes to code: two loops per row, one for the indent and one for the stars. What makes it a parallelogram rather than a rectangle is that the indent changes by exactly one each row, so both the left and right edges form straight diagonal lines.

  1. Run the outer loop for i from 1 to n, one row per pass.
  2. Print i − 1 spaces.
  3. Print 2 × n stars.
  4. Move to the next line.

Key takeaways

  • The width stays at 2n stars on every row.
  • The indent i − 1 grows by one per row, which tilts the block to the right.
  • Use n − i spaces instead to tilt it to the left.
  • Making the width n instead of 2n gives the mirrored rhombus.

Mirrored Parallelogram Star Pattern in C

#include <stdio.h>

int main(void) {
    int n = 4;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++)
            printf(" ");
        for (int j = 1; j <= 2 * n; j++)
            printf("*");
        printf("\n");
    }
    return 0;
}

Mirrored Parallelogram Star Pattern in C++

#include <iostream>
using namespace std;

int main() {
    int n = 4;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++)
            cout << " ";
        for (int j = 1; j <= 2 * n; j++)
            cout << "*";
        cout << endl;
    }
    return 0;
}

Mirrored Parallelogram Star Pattern in Java

public class MirroredParallelogramStar {
    public static void main(String[] args) {
        int n = 4;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i - 1; j++)
                System.out.print(" ");
            for (int j = 1; j <= 2 * n; j++)
                System.out.print("*");
            System.out.println();
        }
    }
}

Mirrored Parallelogram Star Pattern in Python

n = 4

for i in range(1, n + 1):
    for j in range(1, i):
        print(" ", end="")
    for j in range(1, 2 * n + 1):
        print("*", end="")
    print()

Time and space complexity

The program prints one character for each position in the pattern, so for n rows it runs in O(n²) time. It only needs a few loop variables, so the extra memory is O(1).

Frequently asked questions

What is the difference from the mirrored rhombus?

Only the width: a rhombus prints n stars per row, a parallelogram usually 2n. The indent rule is the same.

How do I make a hollow version?

Print stars only on the first and last rows and at the two ends of each row. See the mirrored hollow parallelogram.

Why do both edges slant?

Every row has the same number of stars, so when the start moves one column right, the end moves one column right as well. Both edges therefore follow the same diagonal and stay parallel.

Can the width be any number?

Yes. Replace 2n with any width you like; the slant still comes from the indent.

Authored by

Ghanendra Yadav runs Pattern Programs from Bangalore, India. The site started in 2020 to help students practise loops and logic through pattern programs in C, C++, Java and Python. Every program published here is compiled and run before it goes live, and the output shown is the real output.

Latest articles

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.