C Program - Print Hollow Star Pyramid

#include <stdio.h>

int main() {
    int i, j, space, rows = 5;

    for(i = 1; i <= rows; i++) {
        // Print leading spaces
        for(space = 1; space <= rows - i; space++)
            printf(" ");
        
        // Print stars and hollow spaces
        for(j = 1; j <= 2*i - 1; j++) {
            if(j == 1 || j == 2*i - 1 || i == rows)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}
    *
    * *
  *   *
  *     *
*********

Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...