C program to print hollow pyramid star pattern

  • Write a program in C to print hollow pyramid star pattern using for loops.
  • How to draw an empty equilateral triangle pattern of stars in C.
Hollow pyramid star pattern program's output should be:
     *
    * *
   *   *
  *     *
 *       *
***********

Required Knowledge

Algorithm to print hollow pyramid star pattern using for loop
This program is similar to pyramid star pattern. The only difference is, from first to second last row we will only print first and last star character of any row and we will replace all internal star characters by space character. Then we will print 2*N-1 (N = number of rows in pattern) star characters in last row.

C program to print hollow pyramid star pattern

#include<stdio.h>

int main() {
    int i, space, rows, star=0;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    
    /* printing one row in every iteration */
    for(i = 1; i < rows; i++) {
        /* Printing spaces */
        for(space = 1; space <= rows-i; space++) {
           printf(" ");
        }
        /* Printing stars */
        while(star != (2*i - 1)) {
            if(star==0 || star==2*i-2)
                printf("*");
            else
                printf(" ");
            star++;;
        }
        star=0;
        /* move to next row */
        printf("\n");
    }
    /* print last row */
    for(i=0; i<2*rows-1; i++){
     printf("*");
    }

    return 0;
}
Output
Enter the number of rows
6
     *
    * *
   *   *
  *     *
 *       *
***********

Related Topics
C program pyramid star pattern
C program hollow square star pattern
C program hollow diamond star pattern
C program hollow rectangle pattern
C program hollow diamond star pattern
C program diamond star pattern
C program heart shape star pattern
C program palindrome triangle pattern
C program mirrored right triangle star pattern
List of all C pattern programs