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

Down Arrow Star Pattern

Read summary with AI tools

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
  1. Output
  2. How the down arrow 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

Down Arrow Star Pattern output

Output (n = 5):

    *
    *
    *
    *
*********
 *******
  *****
   ***
    *
Down Arrow Star Pattern layout diagram, row by row (n = 5)
How each row of the down arrow star pattern is built (n = 5). Blue cells are printed characters; grey dots are spaces.

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.

  1. Run the outer loop for i from 1 to n − 1, one row per pass (shaft).
  2. Print n − 1 spaces.
  3. Print 1 stars.
  4. Move to the next line.
  5. Run the outer loop for i from n down to 1, one row per pass (arrow head: inverted pyramid).
  6. Print n − i spaces.
  7. Print 2 × i − 1 stars.
  8. 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 n to 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.

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.