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

Parallelogram Star Pattern

Read summary with AI tools

A slanted block of stars, wider than it is tall. The logic is explained step by step, and the full program is given in C, C++, Java and Python.

Quick answer: Use n rows. On row i, print n − i spaces and then 2 × n stars, then a new line. The shrinking spaces shift each row one step left, which slants the long rows into a parallelogram. The example uses n = 4: 4 rows of 8 stars.

This program is part of the Star Patterns collection.

Table of contents8 sections
  1. Output
  2. How the 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

Parallelogram Star Pattern output

Output (4 rows, 8 stars per row):

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

How the parallelogram star pattern works

Each row prints n − i spaces and then 2n stars. The shrinking indent slants the block to the left as you go down.

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

Key takeaways

  • The star count is fixed at 2 × n; the slant comes only from the leading spaces.
  • It is the rhombus with longer rows: 2 × n stars instead of n.
  • The last row has no spaces, because n − i = 0 when i = n.
  • Total stars: 2 × n × n, which is 32 for n = 4.

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 <= n - i; j++)
            printf(" ");
        for (int j = 1; j <= 2 * n; j++)
            printf("*");
        printf("\n");
    }
    return 0;
}

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 <= n - i; j++)
            cout << " ";
        for (int j = 1; j <= 2 * n; j++)
            cout << "*";
        cout << endl;
    }
    return 0;
}

Parallelogram Star Pattern in Java

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

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

Parallelogram Star Pattern in Python

n = 4

for i in range(1, n + 1):
    for j in range(1, n - i + 1):
        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

How do I change the length of the rows?

Change the limit of the star loop. 2 × n gives rows twice as long as the height; any other number, or a separate width variable, works the same way.

How do I slant it to the right instead?

Print i − 1 spaces instead of n − i; the rows then move right as you go down.

What is the difference from a rhombus?

A rhombus has as many stars per row as it has rows; a parallelogram has longer rows. Compare it with the rhombus star pattern.

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.