C Program to Print Hollow Diamond Star Pattern

Here is a C program to print hollow diamond star pattern. Hollow Diamond star pattern program's output should be:

C program hollow diamond star pattern

Required Knowledge

Algorithm to print hollow diamond star pattern using for loop
This program is similar to diamond star pattern. The only difference is, here we will only print first and last star character of any row and we will replace all internal star characters by space character.

C program to print hollow or empty diamond star pattern

#include<stdio.h>

int main() {
    int i, space, rows=7, star=0;
    
    /* Printing upper triangle */
    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 or star==2*i-2)
                printf("*");
            else 
                printf(" ");
            star++;
        }
        star=0;
        /* move to next row */
        printf("\n");
    }
    rows--;
    /* Printing lower triangle */
    for(i = rows;i >= 1; i--) {
        /* Printing spaces */
        for(space = 0; space <= rows-i; space++) {
           printf(" ");
        }
        /* Printing stars */
        star = 0;
        while(star != (2*i - 1)) {
         if(star == 0 or star==2*i-2)
                printf("*");
            else 
                printf(" ");
            star++;
        }
        printf("\n");
    }

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

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