The trapezium star pattern, called a trapezoid in American English, looks like a pyramid with its top cut off: the first row already has several stars, and every row below is two stars wider.
Quick answer: Row i prints n − i spaces and then 2i + n − 1 stars. The first row starts with n + 1 stars instead of one, which gives the flat top. Each row after that adds one star on each side.
This program is part of the Star Patterns collection.
Table of contents8 sections
Trapezium Star Pattern output
Output (n = 4):
***** ******* ********* ***********

How the trapezium star pattern works
A full pyramid prints 2i − 1 stars on row i. Adding a constant to that count widens every row by the same amount, which slices the point off the pyramid and leaves a flat top. Here the constant is n, so the top row has n + 1 stars. The indent is the same as in a pyramid, so the two slanted sides stay straight.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
n − ispaces. - Print
2 × i + n − 1stars. - Move to the next line.
Key takeaways
- A trapezium is a pyramid with a constant added to every row.
- The star count
2i + n − 1grows by two per row, like a pyramid. - The indent
n − ikeeps both sides slanting evenly. - Changing the constant changes how wide the flat top is.
Trapezium 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 * i + n - 1; j++)
printf("*");
printf("\n");
}
return 0;
}Trapezium 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 * i + n - 1; j++)
cout << "*";
cout << endl;
}
return 0;
}Trapezium Star Pattern in Java
public class TrapeziumStar {
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 * i + n - 1; j++)
System.out.print("*");
System.out.println();
}
}
}Trapezium 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 * i + n):
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 make the top wider or narrower?
Replace the n − 1 in the star count with any number k. The top row then has k + 2 stars, and the rest of the shape follows.
How do I turn it upside down?
Run the rows from n down to 1 with the same spaces and stars. The wide side is then on top.
How do I make a hollow trapezium?
Print stars only on the first and last rows and at the two ends of each row. See the hollow trapezium star pattern.











