C Program to Print Hollow Pyramid Star Pattern

Write a C program to print hollow pyramid star pattern. Hollow pyramid star pattern program's output should be:

C program hollow star pyramid pattern

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.

Here is the matrix representation of the hollow pyramid star pattern. The row numbers are represented by i whereas column numbers are represented by j.

C program hollow pyramid star pattern

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 = 0; i < rows-1; i++) {
        /* Printing spaces */
        for(space = 1; space < rows-i; space++) {
            printf(" ");
        }
        /* Printing stars */
        for (star = 0; star <= 2*i; star++) {
            if(star==0 || star==2*i)
                printf("*");
            else
                printf(" ");
        }
        /* 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