The down arrow star pattern starts with a straight shaft and ends with a wide head that narrows to a point at the bottom. It is the up arrow turned upside down.
Quick answer: Print the shaft first: n − 1 rows of n − 1 spaces and one star. Then print an inverted pyramid by running the rows from n down to 1 with n − i spaces and 2i − 1 stars.
This program is part of the Star Patterns collection.
Table of contents8 sections
Down Arrow Star Pattern output
Output (n = 5):
*
*
*
*
*********
*******
*****
***
*
How the down arrow star pattern works
The inverted pyramid ends with its point in column n, the same column as the shaft, because both use n − 1 spaces before the single star. So the shaft can be printed with a fixed indent and still line up with the point of the head.
- Run the outer loop for
ifrom1ton − 1, one row per pass (shaft). - Print
n − 1spaces. - Print
1stars. - Move to the next line.
- Run the outer loop for
ifromndown to1, one row per pass (arrow head: inverted pyramid). - Print
n − ispaces. - Print
2 × i − 1stars. - Move to the next line.
Key takeaways
- A down arrow is a shaft followed by an inverted pyramid.
- Both the shaft and the point of the head sit in column
n. - The head is the pyramid loop run backwards, from
nto 1. - The up arrow uses the same two parts in the opposite order.
Down Arrow Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 5;
// shaft
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= n - 1; j++)
printf(" ");
for (int j = 1; j <= 1; j++)
printf("*");
printf("\n");
}
// arrow head: inverted pyramid
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int j = 1; j <= 2 * i - 1; j++)
printf("*");
printf("\n");
}
return 0;
}Down Arrow Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
// shaft
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= n - 1; j++)
cout << " ";
for (int j = 1; j <= 1; j++)
cout << "*";
cout << endl;
}
// arrow head: inverted pyramid
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
cout << " ";
for (int j = 1; j <= 2 * i - 1; j++)
cout << "*";
cout << endl;
}
return 0;
}Down Arrow Star Pattern in Java
public class DownArrowStar {
public static void main(String[] args) {
int n = 5;
// shaft
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= n - 1; j++)
System.out.print(" ");
for (int j = 1; j <= 1; j++)
System.out.print("*");
System.out.println();
}
// arrow head: inverted pyramid
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
System.out.print(" ");
for (int j = 1; j <= 2 * i - 1; j++)
System.out.print("*");
System.out.println();
}
}
}Down Arrow Star Pattern in Python
n = 5
# shaft
for i in range(1, n):
for j in range(1, n):
print(" ", end="")
for j in range(1, 2):
print("*", end="")
print()
# arrow head: inverted pyramid
for i in range(n, 0, -1):
for j in range(1, n - i + 1):
print(" ", end="")
for j in range(1, 2 * i):
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
Why does the head start with the widest row?
The arrow points down, so its widest part has to be at the top of the head. Running i from n down to 1 prints the widest row first.
How do I make the head hollow?
Print stars only on the first head row and at the two ends of each row, as in the hollow inverted pyramid.
How do I let the user choose the size?
Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.











