The up arrow star pattern is a pyramid with a straight shaft underneath it, so the whole shape points up. It joins two very simple pieces, and the only care needed is lining the shaft up with the tip.
Quick answer: Print a pyramid for the head: row i has n − i spaces and 2i − 1 stars. Then print the shaft: n − 1 rows, each with n − 1 spaces and one star, which puts the star in the same column as the tip.
This program is part of the Star Patterns collection.
Table of contents8 sections
Up Arrow Star Pattern output
Output (n = 5):
*
***
*****
*******
*********
*
*
*
*
How the up arrow star pattern works
The tip of the pyramid sits in column n, after n − 1 spaces. The shaft just repeats that single star for a few rows, so every shaft row uses the same n − 1 spaces. Choosing n − 1 shaft rows keeps the arrow in proportion, but any length works.
- Run the outer loop for
ifrom1ton, one row per pass (arrow head: a pyramid). - Print
n − ispaces. - Print
2 × i − 1stars. - Move to the next line.
- Run the outer loop for
ifrom1ton − 1, one row per pass (shaft: one centred star per row). - Print
n − 1spaces. - Print
1stars. - Move to the next line.
Key takeaways
- The arrow is a pyramid plus a straight shaft.
- The shaft star is indented
n − 1spaces, the same as the tip. - The shaft length is free;
n − 1rows looks balanced. - Swap the order of the two parts and use an inverted pyramid for a down arrow.
Up Arrow Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 5;
// arrow head: a pyramid
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int j = 1; j <= 2 * i - 1; j++)
printf("*");
printf("\n");
}
// shaft: one centred star per row
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");
}
return 0;
}Up Arrow Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
// arrow head: a pyramid
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++)
cout << " ";
for (int j = 1; j <= 2 * i - 1; j++)
cout << "*";
cout << endl;
}
// shaft: one centred star per row
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;
}
return 0;
}Up Arrow Star Pattern in Java
public class UpArrowStar {
public static void main(String[] args) {
int n = 5;
// arrow head: a pyramid
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 - 1; j++)
System.out.print("*");
System.out.println();
}
// shaft: one centred star per row
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();
}
}
}Up Arrow Star Pattern in Python
n = 5
# arrow head: a pyramid
for i in range(1, n + 1):
for j in range(1, n - i + 1):
print(" ", end="")
for j in range(1, 2 * i):
print("*", end="")
print()
# shaft: one centred star per row
for i in range(1, n):
for j in range(1, n):
print(" ", end="")
for j in range(1, 2):
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 shaft thicker?
Print three stars per shaft row with n − 2 spaces in front. The shaft stays centred because it grows by one star on each side.
How do I point the arrow down?
Print the shaft first and then an inverted pyramid, as in the down arrow star pattern.
Can I draw left and right arrows too?
Yes, the site has a right arrow and a left arrow. They grow and shrink along the rows instead of the columns.











