C Program to Print Diamond Star Pattern

Here is a C program to print diamond star pattern using for loop. Diamond star pattern program's output should be:

C program diamond star pattern

Required Knowledge

Algorithm to print diamond star pattern using loop
Diamond star pattern is a combination of pyramid star pattern and inverse pyramid star pattern. This program is combination of both, it first prints a pyramid followed by a reverse pyramid star pattern.

C program to print 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)) {
            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)) {
            printf("*");
            star++;
        }
        printf("\n");
    }

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

Related Topics
C program hollow diamond star pattern
C program pyramid star pattern
C program hollow pyramid star pattern
C program inverted right triangle pattern
C program hollow rectangle pattern
C program mirrored right triangle star pattern
C program heart shape star pattern
C program binary triangle pattern
C program hut star pattern
List of all C pattern programs