Star Pattern Programs in C

This article shows the list of available Star Pattern Programs in C programming language with an example of each using the for loop, while loop, functions, and do while loop.

Apart from the Star Pattern Programs, you can print Alphabet and Number patterns using the C programming language. Before you start reading this, I suggest you refer to the C tutorial and C Examples articles to understand the language and the remaining programs.

Star Pattern Programs in C

The following is the list of C programs to Print star patterns and shapes.

C Program to Print Diamond Star Pattern

The below example uses a nested for loop to iterate rows and print the diamond star pattern. Within this section, we show you different kinds of diamond patterns. For more examples >> Click Here.

#include<stdio.h>

void loopLogic(int rows, int i){
    for(int j = 1; j <= rows - i; j++)
    {
        printf(" ");
    }
    for(int k = 1; k <= i * 2 - 1; k++)
    {
        printf("*");
    }
    printf("\n");
}

int main(void)
{
    int i, rows;
    
    printf("Enter Diamond Rows =  ");
    scanf("%d", &rows);
    
    for(i = 1; i <= rows; i++)
    {
        loopLogic(rows, i);
    }
    
    for(i = rows - 1; i > 0; i--)
    {
        loopLogic(rows, i);
    }
}

Output.

Enter Diamond Rows =  8
       *
      ***
     *****
    *******
   *********
  ***********
 *************
***************
 *************
  ***********
   *********
    *******
     *****
      ***
       *

Half Diamond Pattern of Stars

For more examples to print the Half Diamond Pattern of Stars >> Click Here.

#include<stdio.h>
void result(int r, int i)
{
    for (int j = 1; j <= i; j++) {
        printf("*");
    }
    printf("\n");
}
int main(void) {
    int i, r;
    
    printf("Enter Half Diamond Pattern Rows =  ");
    scanf("%d", &r);
    
    for (i = 1; i <= r; i++) {
        result(r, i);
    }
    for (i = r - 1; i > 0; i--) {
        result(r, i);
    }
}

Output

Enter Half Diamond Pattern Rows =  12
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
***********
**********
*********
********
*******
******
*****
****
***
**
*

Hollow Diamond Stars Pattern

For more examples of the Hollow Diamond Stars Pattern >> Click Here.

#include<stdio.h>
void result(int r, int i)
{
    for (int j = 1; j <= r - i; j++) {
        printf(" ");
    }
    for (int k = 1; k <= i * 2 - 1; k++) {
        if (k == 1 || k == i * 2 - 1) {
            printf("*");
        } else {
            printf(" ");
        }
    }
    printf("\n");
}
int main(void) {
    int i, r;
    
    printf("Enter Hollow Diamond Pattern Rows =  ");
    scanf("%d", &r);
    
    for (i = 1; i <= r; i++) {
        result(r, i);
    }
    for (i = r - 1; i > 0; i--) {
        result(r, i);
    }
}

Output

Enter Hollow Diamond Pattern Rows =  8
       *
      * *
     *   *
    *     *
   *       *
  *         *
 *           *
*             *
 *           *
  *         *
   *       *
    *     *
     *   *
      * *
       *

Hollow Diamond inside a Square Pattern

For more examples of the C program to print Hollow Diamond inside a Square Pattern star pattern >> Click Here.

#include<stdio.h>
int main(void)
{
    int i, j, k, r;
    
    printf("Enter Hollow Diamond inside Square Rows =  ");
    scanf("%d", &r);
    
    for (i = 0 ; i < r; i++ )
    {
        for (j = 0 ; j < r; j++ )
        {
            if(j < r - i) {
                printf("*");
            }
            else {
                printf(" ");
            }
        }
        for (k = 0 ; k < r; k++ )
        {
            if (k < i ) {
                printf(" ");
            }
            else {
                printf("*");
            }
        }
        printf("\n");
    }
    
    for (i = 1 ; i <= r; i++ )
    {
        for (j = 0 ; j < r; j++ )
        {
            if(j < i) {
                printf("*");
            }
            else {
                printf(" ");
            }
        }
        for (k = 0 ; k < r; k++ )
        {
            if (k < r - i ) {
                printf(" ");
            }
            else {
                printf("*");
            }
        }
        printf("\n");
    }
}

Output

Enter Hollow Diamond inside Square Rows =  13
**************************
************  ************
***********    ***********
**********      **********
*********        *********
********          ********
*******            *******
******              ******
*****                *****
****                  ****
***                    ***
**                      **
*                        *
*                        *
**                      **
***                    ***
****                  ****
*****                *****
******              ******
*******            *******
********          ********
*********        *********
**********      **********
***********    ***********
************  ************
**************************

Mirrored Half Diamond Star Pattern

For more examples of the Mirrored Half Diamond Star Pattern >> Click Here.

#include<stdio.h>
void result(int r, int i)
{
    for (int j = 1; j <= r - i; j++) {
        printf(" ");
    }
    for (int k = 1; k <= i; k++) {
        printf("*");
    }
    printf("\n");
}
int main(void) {
    int i, r;
    
    printf("Enter Mirrored Half Diamond Pattern Rows =  ");
    scanf("%d", &r);
    
    for (i = 1; i <= r; i++) {
        result(r, i);
    }
    for (i = r - 1; i > 0; i--) {
        result(r, i);
    }
}

Output

Enter Mirrored Half Diamond Pattern Rows =  11
          *
         **
        ***
       ****
      *****
     ******
    *******
   ********
  *********
 **********
***********
 **********
  *********
   ********
    *******
     ******
      *****
       ****
        ***
         **
          *

C Program to Print Pyramid Star Pattern

This C program uses the nested for loop structure to print the Pyramid Star Pattern. I suggest you refer to the For Loop article to understand the logic. For more examples of Pyramids >> Click Here.

#include <stdio.h>
 
int main(void)
{
    int rows, i, j, k;
    
    printf("Enter Pyramid Rows:  ");
    scanf("%d", &rows);
    
    for ( i = 1 ; i <= rows; i++ )
    {
        for ( j = 1 ; j <= rows-i; j++ )
        {
            printf(" ");
        }
        for (k = 1; k <= (2 * i - 1); k++)
        {
            printf("*");
        }
        printf("\n");
    }
}
Enter Pyramid Rows:  9
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************

Inverted Pyramid Stars Pattern

For more examples of an inverted pyramid of stars pattern >> Click Here.

#include<stdio.h>
int main(void)
{
    int rows;
      
    printf("Enter Inverted Pyramid Rows:  ");
    scanf("%d", &rows);
      
    for (int i = rows ; i >= 1; i-- )
      {
        for (int j = 0 ; j <= rows-i; j++ )
        {
            printf(" ");
        }
        for (int k = 0; k < (2 * i - 1); k++)
        {
            printf("*");
        }
        printf("\n");
      }
  }

Output

Enter Inverted Pyramid Rows:  9
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *

Hollow Pyramid Star Pattern

For more C program examples of printing the hollow pyramid of star pattern >> Click Here.

#include<stdio.h>
int main(void)
{
    int i, j, rows;
    printf("Enter Hollow Pyramid Star Rows =  ");
    
    scanf("%d", &rows);
    for(i = 1; i <= rows; i++)
    {
        for(j = 1; j <= rows - i; j++)
        {
            printf(" ");
        }
        if(i == 1 || i == rows)
        {
            for(j = 1; j <= i * 2 - 1; j++)
            {
                printf("*");
            }
        }
        else
        {
            for(j = 1; j <= i * 2 - 1; j++)
            {
                if(j == 1 || j == i * 2 - 1)
                {
                    printf("*");
                }
                else
                {
                    printf(" ");
                }
            }
        }
        printf("\n");
    }
}

Output

Enter Hollow Pyramid Star Rows =  13
            *
           * *
          *   *
         *     *
        *       *
       *         *
      *           *
     *             *
    *               *
   *                 *
  *                   *
 *                     *
*************************

Hollow Inverted Pyramid Pattern of Stars

For more examples on Hollow Inverted Pyramid Stars Pattern >> Click Here.

#include<stdio.h>
int main(void)
{
    int i, j, rows;
    printf("Enter Hollow Inverted Pyramid Star Rows =  ");
    scanf("%d", &rows);
    
    for(i = rows; i > 0; i--)
    {
        for(j = 1; j <= rows - i; j++)
        {
            printf(" ");
        }
        
        if(i == 1 || i == rows)
        {
            for(j = 1; j <= i * 2 - 1; j++)
            {
                printf("*");
            }
        }
        else
        {
            for(j = 1; j <= i * 2 - 1; j++)
            {
                if(j == 1 || j == i * 2 - 1)
                {
                    printf("*");
                }
                else
                {
                    printf(" ");
                }
            }
        }
        printf("\n");
    }
}

Output

Enter Hollow Inverted Pyramid Star Rows =  12
***********************
 *                   *
  *                 *
   *               *
    *             *
     *           *
      *         *
       *       *
        *     *
         *   *
          * *
           *

C Program to Print Right Angled Triangle Star Pattern

For more information on the Right Angled Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    printf("Enter Right Angled Triangle Rows =  ");
    scanf("%d", &n);
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output

Star Pattern Programs in C

Hollow Right Triangle Pattern

For more examples of the Hollow Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    
    printf("Enter Hollow Right Triangle Rows =  ");
    scanf("%d", &n);
    
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            if(i == 1 || i == n || j == 1 || j == i)
                printf("* ");
            else
            {
                printf("  ");
            }
        }
        printf("\n");
    }
}

Output.

Enter Hollow Right Triangle Rows =  12
* 
* * 
*   * 
*     * 
*       * 
*         * 
*           * 
*             * 
*               * 
*                 * 
*                   * 
* * * * * * * * * * * *

Mirrored Right Triangle Pattern

For more examples of the Mirrored Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    
    printf("Enter the Number of Rows :  ");
    scanf("%d", &n);
    
    for (int i = 1 ; i <= n; i++ )
    {
        for (int j = 1 ; j <= n; j++ )
        {
            if(j <= n-i)
            {
                printf(" ");
            }
            else
            {
                printf("*");
            }
        }
        printf("\n");
    }
}

Output.

Enter the Number of Rows :  14
             *
            **
           ***
          ****
         *****
        ******
       *******
      ********
     *********
    **********
   ***********
  ************
 *************
**************

Hollow Mirrored Right Triangle Pattern

For more examples of the Hollow Mirrored Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, n;
    printf("Enter Hollow Mirrored Right Triangle Rows =  ");
    scanf("%d", &n);
    
    for(int i = 1; i <= n; i++)
    {
        for(j = 1; j <= n - i; j++)
        {
            printf(" ");
        }
        for(j = 1; j <= i; j++)
        {
            if(j == 1 || j == i || i == 1 || i == n)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }
}

Output.

Enter Hollow Mirrored Right Triangle Rows =  15
              *
             **
            * *
           *  *
          *   *
         *    *
        *     *
       *      *
      *       *
     *        *
    *         *
   *          *
  *           *
 *            *
***************

Reversed Mirrored Right Triangle

For more examples of the Reversed Mirrored Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    
    printf("Enter the Number of Rows =  ");
    scanf("%d", &n);
    
    for (int i = 1 ; i <= n; i++ )
    {
        for (int j = 1 ; j <= n; j++ )
        {
            if(j < i)
            {
                printf(" ");
            }
            else
            {
                printf("*");
            }
        }
        printf("\n");
    }
}

Output.

Enter the Number of Rows =  13
*************
 ************
  ***********
   **********
    *********
     ********
      *******
       ******
        *****
         ****
          ***
           **
            *

Inverted Right Triangle

For more examples of the Inverted Right Triangle Star Pattern Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    
    printf("Enter the Number of Rows =  ");
    scanf("%d", &n);
    
    for (int i = n ; i > 0 ; i-- )
      {
          for (int j = i ; j > 0 ; j-- )
          {
              printf("* ");
          }
          printf("\n");
      }
}

Output.

Enter the Number of Rows =  12
* * * * * * * * * * * * 
* * * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * 
* * * * * * * * 
* * * * * * * 
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 
* 

Hollow Inverted Right Triangle Pattern

For more examples of the Hollow Inverted Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int n;
    
    printf("Enter the Number of Rows =  ");
    scanf("%d", &n);
    
    for (int i = n ; i > 0 ; i-- )
    {
        for (int j = i ; j > 0 ; j-- )
        {
            if(i == 1 || i == n  || j == 1 || j == i)
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
}

Output.

Enter the Number of Rows =  16
****************
*             *
*            *
*           *
*          *
*         *
*        *
*       *
*      *
*     *
*    *
*   *
*  *
* *
**
*

Inverted Mirrored Right Triangle

For more examples of the Inverted Mirrored Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, n;
    printf("Enter Inverted Mirrored Right Triangle Rows =  ");
    scanf("%d", &n);
    
    for(i = n; i > 0; i--)
    {
        for(j = n - i; j > 0; j--)
        {
            printf(" ");
        }
        for(j = 0; j < i; j++)
        {
            printf("*");
        }
        printf("\n");
    }
}

Output.

Enter Inverted Mirrored Right Triangle Rows =  10
**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *

Hollow Inverted Mirrored Right Triangle

For more examples of the Hollow Inverted Mirrored Right Triangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, n;
    printf("Enter Hollow Inverted Mirrored Right Triangle Rows =  ");
    scanf("%d", &n);
    
    for(i = n; i > 0; i--)
    {
        for(j = n - i; j > 0; j--)
        {
            printf(" ");
        }
        for(j = 1; j <= i; j++)
        {
            if(i == 1 || i == n || j == 1 || j == i)
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
}

Output.

Enter Hollow Inverted Mirrored Right Triangle Rows =  13
*************
 *          *
  *         *
   *        *
    *       *
     *      *
      *     *
       *    *
        *   *
         *  *
          * *
           **
            *

C program to Print Rectangle Star Pattern

For more examples of the Rectangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int rows, columns;
    
    printf("Enter the Number of rows = ");
    scanf("%d", &rows);
    
    printf("Enter the Number of Columns = ");
    scanf("%d", &columns);
    
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < columns; j++)
        {
            printf("*");
        }
        printf("\n");
    }
}

Output.

Enter the Number of rows = 10
Enter the Number of Columns = 14
**************
**************
**************
**************
**************
**************
**************
**************
**************
**************

Hollow Rectangle Star Pattern

For more examples of the Hollow Rectangle Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int rows, columns;
    
    printf("Enter the Number of rows = ");
    scanf("%d", &rows);
    
    printf("Enter the Number of Columns = ");
    scanf("%d", &columns);
    
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < columns; j++)
        {
            if(i == 0 || i == rows-1 || j == 0 || j == columns-1)
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
}

Output.

Enter the Number of rows = 8
Enter the Number of Columns = 16
****************
*              *
*              *
*              *
*              *
*              *
*              *
****************

C Program to Print Rhombus Pattern of Stars *

This example prints the Rhombus Pattern of stars. For more examples >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int rows;
    printf("Enter Rhombus Star Pattern Rows =  ");
    scanf("%d", &rows);
    
    for(int i = rows; i >= 1; i--)
    {
        for(int j = 1; j <= i - 1; j++)
        {
            printf("  ");
        }
        for(int k = 1; k <= rows; k++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output

Enter Rhombus Star Pattern Rows =  14
                          * * * * * * * * * * * * * * 
                        * * * * * * * * * * * * * * 
                      * * * * * * * * * * * * * * 
                    * * * * * * * * * * * * * * 
                  * * * * * * * * * * * * * * 
                * * * * * * * * * * * * * * 
              * * * * * * * * * * * * * * 
            * * * * * * * * * * * * * * 
          * * * * * * * * * * * * * * 
        * * * * * * * * * * * * * * 
      * * * * * * * * * * * * * * 
    * * * * * * * * * * * * * * 
  * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * 

Mirrored Rhombus Star Pattern

For more examples of the Mirrored Rhombus Star Pattern >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int rows;
    printf("Enter Mirrored Rhombus Star Pattern Rows =  ");
    scanf("%d", &rows);
    
    for(int i = 1; i <= rows; i++)
    {
        for(int j = 1; j < i; j++)
        {
            printf("  ");
        }
        for(int k = 1; k <= rows; k++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output.

Enter Mirrored Rhombus Star Pattern Rows =  13
* * * * * * * * * * * * * 
  * * * * * * * * * * * * * 
    * * * * * * * * * * * * * 
      * * * * * * * * * * * * * 
        * * * * * * * * * * * * * 
          * * * * * * * * * * * * * 
            * * * * * * * * * * * * * 
              * * * * * * * * * * * * * 
                * * * * * * * * * * * * * 
                  * * * * * * * * * * * * * 
                    * * * * * * * * * * * * * 
                      * * * * * * * * * * * * * 
                        * * * * * * * * * * * * * 

Hollow Rhombus Star Pattern

For more examples of printing the Hollow Rhombus Star Pattern >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int i, j, k, rows;
    printf("Enter Hollow Rhombus Star Pattern Rows =  ");
    scanf("%d", &rows);
    
    for(i = rows; i >= 1; i--)
    {
        for(j = 1; j <= i - 1; j++)
        {
            printf(" ");
        }
        for(k = 1; k <= rows; k++)
        {
            if(i == 1 || i == rows || k == 1 || k == rows)
            {
                printf("* ");
            }
            else
            {
                printf("  ");
            }
        }
        printf("\n");
    }
}

Output.

Enter Hollow Rhombus Star Pattern Rows =  9
        * * * * * * * * * 
       *               * 
      *               * 
     *               * 
    *               * 
   *               * 
  *               * 
 *               * 
* * * * * * * * * 

Hollow Mirrored Rhombus Star Pattern

For more Hollow Mirrored Rhombus Star Pattern examples, Click Here.

#include<stdio.h>
 
int main(void)
{
    int i, j, rows;
    printf("Enter Hollow Mirrored Rhombus Rows =  ");
    scanf("%d", &rows);
    
    for(i = 1; i <= rows; i++)
    {
        for(j = i; j > 0; j--)
        {
            printf(" ");
        }
        
        if(i == 1 || i == rows)
        {
            for(j = 1; j <= rows; j++)
            {
                printf("*");
            }
        }
        else
        {
            for(j = 1; j <= rows; j++)
            {
                if(j == 1 || j == rows)
                {
                    printf("*");
                }
                else
                {
                    printf(" ");
                }
            }
        }
        printf("\n");
    }
}

Output.

Enter Hollow Mirrored Rhombus Rows =  12
 ************
  *          *
   *          *
    *          *
     *          *
      *          *
       *          *
        *          *
         *          *
          *          *
           *          *
            ************

C Program to Print Square Pattern of Stars *

This example prints the Square Star Pattern. For more examples >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int Side;
    
    printf("Enter Any Side of a Square = ");
    scanf("%d", &Side);
    
    for(int i = 0; i < Side; i++)
    {
        for(int j = 0; j < Side; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output

Enter Any Side of a Square = 12
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * * 

Hollow Square Pattern With Diagonals

For more examples of the Hollow Square With Diagonals Pattern >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int r;
    
    printf("Enter Hollow Square with Diagonals Rows =  ");
    scanf("%d", &r);
    
    for(int i = 1; i <= r; i++)
    {
        for(int  j = 1; j <= r; j++)
        {
            if(i == 1 || i == r || i == j || j == 1 || j == r || j == r - i + 1)
            {
                printf("* ");
            }
            else
            {
                printf("  ");
            }
        }
        printf("\n");
    }
}

Output.

Enter Hollow Square with Diagonals Rows =  14
* * * * * * * * * * * * * * 
* *                     * * 
*   *                 *   * 
*     *             *     * 
*       *         *       * 
*         *     *         * 
*           * *           * 
*           * *           * 
*         *     *         * 
*       *         *       * 
*     *             *     * 
*   *                 *   * 
* *                     * * 
* * * * * * * * * * * * * * 

Hollow Square Star Pattern

For more examples of Printing the Hollow Square Star Pattern >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int Side;
    
    printf("Enter Any Side of a Square = ");
    scanf("%d", &Side);
    
    for(int i = 0; i < Side; i++)
    {
        for(int j = 0; j < Side; j++)
        {
            if(i == 0 || i == Side-1 || j == 0 || j == Side-1)
            {
                printf("* ");
            }
            else
            {
                printf("  ");
            }
        }
        printf("\n");
    }
}

Output.

Enter Any Side of a Square = 9
* * * * * * * * * 
*               * 
*               * 
*               * 
*               * 
*               * 
*               * 
*               * 
* * * * * * * * * 

C Program to Print Sandglass Pattern of Stars *

This example uses the for loop to print the Sandglass Pattern of Stars. For more examples >> Click Here.

#include <stdio.h>

void loopLogic(int rows, int i)
{
    for (int j = 1; j < i; j++ )
    {
        printf(" ");
    }
   for (int k = i; k <= rows; k++ )
    {
        printf("* ");
    }
    printf("\n");
}

int main(void)  {
    int i, rows;
    
    printf("Enter Sandglass Star Pattern Rows = ");
    scanf("%d",&rows);
    
    for (i = 1; i <= rows; i++)
    {
        loopLogic(rows, i);
    }
    
    for (i = rows - 1; i >= 1; i--)
    {
        loopLogic(rows, i);
    }
}

Output

Enter Sandglass Star Pattern Rows = 11
* * * * * * * * * * * 
 * * * * * * * * * * 
  * * * * * * * * * 
   * * * * * * * * 
    * * * * * * * 
     * * * * * * 
      * * * * * 
       * * * * 
        * * * 
         * * 
          * 
         * * 
        * * * 
       * * * * 
      * * * * * 
     * * * * * * 
    * * * * * * * 
   * * * * * * * * 
  * * * * * * * * * 
 * * * * * * * * * * 
* * * * * * * * * * * 

Hollow Sandglass Star Pattern

For more examples of the Hollow Sandglass Star Pattern >> Click Here.

#include <stdio.h>

void loopLogic(int rows, int i)
{
    for (int j = 1; j < i; j++ )
    {
        printf(" ");
    }
    for (int k = i; k <= rows; k++ )
    {
        if (i == 1 || k == i || k == rows)
        {
            printf("* ");
        }
        else
        {
            printf("  ");
        }
    }
    printf("\n");
}

int main(void)  {
    int i, rows;
    
    printf("Enter Hollow Sandglass Star Pattern Rows = ");
    scanf("%d",&rows);
    
    for (i = 1; i <= rows; i++)
    {
        loopLogic(rows, i);
    }
    
    for (i = rows - 1; i >= 1; i--)
    {
        loopLogic(rows, i);
    }
}

Output

Enter Hollow Sandglass Star Pattern Rows = 8
* * * * * * * * 
 *           * 
  *         * 
   *       * 
    *     * 
     *   * 
      * * 
       * 
      * * 
     *   * 
    *     * 
   *       * 
  *         * 
 *           * 
* * * * * * * * 

C Program to Print Triangle Star Pattern

The below Triagle program uses the nested for loops to iterate the rows and columns and prints the stars. For more information on the Triangle Pattern of Stars >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int n;
    printf("Enter Triangle Rows =  ");
    scanf("%d", &n);
    
    for (int i = 1 ; i <= n; i++ )
    {
        for (int j = 0 ; j < n - i; j++ )
        {
            printf("  ");
        }
        for (int k = 0 ; k < i * 2 - 1; k++ )
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output

Enter Triangle Rows =  15
                            * 
                          * * * 
                        * * * * * 
                      * * * * * * * 
                    * * * * * * * * * 
                  * * * * * * * * * * * 
                * * * * * * * * * * * * * 
              * * * * * * * * * * * * * * * 
            * * * * * * * * * * * * * * * * * 
          * * * * * * * * * * * * * * * * * * * 
        * * * * * * * * * * * * * * * * * * * * * 
      * * * * * * * * * * * * * * * * * * * * * * * 
    * * * * * * * * * * * * * * * * * * * * * * * * * 
  * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

Hollow Triangle Star Pattern

For information about the Hollow Triangle Pattern of Stars >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, k, n;
    
    printf("Enter Hollow Triangle Rows =  ");
    scanf("%d", &n);
    
    for (i = 1 ; i <= n; i++ )
    {
        for ( j = 1 ; j <= n - i; j++ )
        {
            printf("  ");
        }
        for ( k = 1 ; k <= i * 2 - 1; k++ )
        {
            if (i == 1 || i == n || k == 1 || k == i * 2 - 1 )
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }
}

Output

Enter Hollow Triangle Rows =  14
                          * 
                        *   * 
                      *       * 
                    *           * 
                  *               * 
                *                   * 
              *                       * 
            *                           * 
          *                               * 
        *                                   * 
      *                                       * 
    *                                           * 
  *                                               * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * 

Inverted Triangle Star Pattern

For information about the Inverted Triangle Pattern of Stars >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int n;
    printf("Enter Inverted Triangle Rows =  ");
    scanf("%d", &n);
    
    for (int i = n ; i > 0; i-- )
    {
        for (int j = 1 ; j <= n - i; j++ )
        {
            printf("  ");
        }
        for (int  k = 1 ; k <= i * 2 - 1; k++ )
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output

Enter Inverted Triangle Rows =  16
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    * * * * * * * * * * * * * * * * * * * * * * * * * * * 
      * * * * * * * * * * * * * * * * * * * * * * * * * 
        * * * * * * * * * * * * * * * * * * * * * * * 
          * * * * * * * * * * * * * * * * * * * * * 
            * * * * * * * * * * * * * * * * * * * 
              * * * * * * * * * * * * * * * * * 
                * * * * * * * * * * * * * * * 
                  * * * * * * * * * * * * * 
                    * * * * * * * * * * * 
                      * * * * * * * * * 
                        * * * * * * * 
                          * * * * * 
                            * * * 
                              * 

Downward Triangle Star Pattern

For information about the Downward Triangle Star Pattern >> Click Here.

#include<stdio.h>
 
int main(void)
{
    int n;
    printf("Enter Downward Triangle Rows =  ");
    scanf("%d", &n);
    
    for (int i = n - 1; i >= 0; i-- )
    {
        for (int j = 0 ; j <= i; j++ )
        {
            printf("*  ");
        }
        printf("\n");
    }
}

Output

Enter Downward Triangle Rows =  13
*  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  
*  *  *  *  *  *  
*  *  *  *  *  
*  *  *  *  
*  *  *  
*  *  
* 

Right Pascal Triangle Star Pattern

For more information on the Right Pascal Triangle Star Pattern >> Click Here.

#include<stdio.h>
void logicOutput(int n, int i)
{
    for (int j = 0; j < i; j++)
    {
        printf("* ");
    }
    printf("\n");
}

int main(void)
{
    int i, n;
    
    printf("Enter Right Pascal Triangle Rows =  ");
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)
    {
        logicOutput(n, i);
    }
    for (i = n; i >= 0; i--)
    {
        logicOutput(n, i);
    }
}

Output

Enter Right Pascal Triangle Rows =  12

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* * * * * * * * 
* * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * 
* * * * * * * * 
* * * * * * * 
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 
*

Left Pascal Triangle Star Pattern

For more information on the Left Pascal Triangle Star Pattern >> Click Here.

#include<stdio.h>

void logicOutput(int n, int i)
{
    int j, k;
    for (j = i; j < n; j++)
    {
        printf("  ");
    }
    for (k = 1; k <= i; k++)
    {
        printf("* ");
    }
    printf("\n");
}

int main(void)
{
    int i, n;
    
    printf("Enter Left Pascal Triangle Rows =  ");
    scanf("%d", &n);
    
    for (i = 1; i <= n; i++) {
        logicOutput(n, i);
    }
    for (i = n - 1; i >= 1; i--) {
        logicOutput(n, i);
    }
}

Output

Enter Left Pascal Triangle Rows =  13
                        * 
                      * * 
                    * * * 
                  * * * * 
                * * * * * 
              * * * * * * 
            * * * * * * * 
          * * * * * * * * 
        * * * * * * * * * 
      * * * * * * * * * * 
    * * * * * * * * * * * 
  * * * * * * * * * * * * 
* * * * * * * * * * * * * 
  * * * * * * * * * * * * 
    * * * * * * * * * * * 
      * * * * * * * * * * 
        * * * * * * * * * 
          * * * * * * * * 
            * * * * * * * 
              * * * * * * 
                * * * * * 
                  * * * * 
                    * * * 
                      * * 
                        *

Hollow Left Pascal Triangle Star Pattern

For more information on the Hollow Left Pascal Triangle Star Pattern >> Click Here.

#include<stdio.h>
void logicOutput(int n, int i)
{
    for (int j = i; j < n; j++)  {
        printf("  ");
    }
    for (int k = 1; k <= i; k++)  {
        if (k == 1 || k == i )
            printf("* ");
        else
            printf("  ");
    }
    printf("\n");
}
int main(void)  {
    int i, n;
    
    printf("Enter Hollow Left Pascal Triangle Rows =  ");
    scanf("%d", &n);
    
    for (i = 1; i <= n; i++)  {
        logicOutput(n, i);
    }
    for (i = n - 1; i >= 1; i--)  {
        logicOutput(n, i);
    }
}

Output

Enter Hollow Left Pascal Triangle Rows =  12
                      * 
                    * * 
                  *   * 
                *     * 
              *       * 
            *         * 
          *           * 
        *             * 
      *               * 
    *                 * 
  *                   * 
*                     * 
  *                   * 
    *                 * 
      *               * 
        *             * 
          *           * 
            *         * 
              *       * 
                *     * 
                  *   * 
                    * * 
                      *

Hollow Right Pascal Triangle Star Pattern

For more details on the Hollow Right Pascal Triangle Star Pattern >> Click Here.

#include<stdio.h>

void logicOutput(int n, int i)
{
    for (int j = 1; j <= i; j++)  {
        if (j == 1 || j == i )
            printf("* ");
        else
            printf("  ");
    }
    printf("\n");
}

int main(void)
{
    int i, n;
    
    printf("Enter Hollow Right Pascal Triangle Rows =  ");
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)  {
        logicOutput(n, i);
    }
    for (i = n; i >= 0; i--) {
        logicOutput(n, i);
    }
}

Output

Enter Hollow Right Pascal Triangle Rows =  10

* 
* * 
*   * 
*     * 
*       * 
*         * 
*           * 
*             * 
*               * 
*                 * 
*               * 
*             * 
*           * 
*         * 
*       * 
*     * 
*   * 
* * 
* 

Remaining Star Pattern Programs in C

Christmas Tree Star Pattern

For more examples of the Christmas Tree Star Pattern >> Click Here.

#include <stdio.h>
int main(void)
{
    int width, height, sp, i, j, k, n = 1;

    printf("Enter Chirstmas Tree Width & Height = ");
    scanf("%d %d", &width, &height);

    sp = width * height;

    for (int x = 1; x <= height; x++)
    {
        for (i = n; i <= width; i++)
        {
            for (j = sp; j >= i; j--)
            {
                printf(" ");
            }
            for (k = 1; k <= i; k++)
            {
                printf("* ");
            }
            printf("\n");
        }
        n = n + 2;
        width = width + 2;
    }
    for (i = 1; i <= height - 1; i++)
    {
        for (j = sp - 3; j >= 0; j--)
        {
            printf(" ");
        }
        for (k = 1; k <= height - 1; k++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output.

Enter Chirstmas Tree Width & Height = 6 4
                        * 
                       * * 
                      * * * 
                     * * * * 
                    * * * * * 
                   * * * * * * 
                      * * * 
                     * * * * 
                    * * * * * 
                   * * * * * * 
                  * * * * * * * 
                 * * * * * * * * 
                    * * * * * 
                   * * * * * * 
                  * * * * * * * 
                 * * * * * * * * 
                * * * * * * * * * 
               * * * * * * * * * * 
                  * * * * * * * 
                 * * * * * * * * 
                * * * * * * * * * 
               * * * * * * * * * * 
              * * * * * * * * * * * 
             * * * * * * * * * * * * 
                      * * * 
                      * * * 
                      * * * 

Exponentially Increasing Star Pattern

For more examples of the Exponentially Increasing Star Pattern >> Click Here.

#include <stdio.h>
#include <math.h>
 
int main(void)
{
    int Rows;
    
    printf("Enter the Number of Rows:  ");
    scanf("%d", &Rows);
    
    for (int i = 0 ; i <= Rows; i++ )
    {
        for (int j = 1 ; j <= pow(2, i); j++ )
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output.

Enter the Number of Rows:  5
* 
* * 
* * * * 
* * * * * * * * 
* * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

Left Arrow Star Pattern

For more examples of the Left Arrow Star pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, n;
    printf("Enter Left Arrow Star Pattern Rows =  ");
    scanf("%d", &n);
    
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n - i; j++)
        {
            printf(" ");
        }
        for(j = i; j <= n; j++)
        {
            printf("*");
        }
        printf("\n");
    }
    
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j < i; j++)
        {
            printf(" ");
        }
        for(j = 1; j <= i; j++)
        {
            printf("*");
        }
        printf("\n");
    }
}

Output.

Enter Left Arrow Star Pattern Rows =  7
      *******
     ******
    *****
   ****
  ***
 **
*
*
 **
  ***
   ****
    *****
     ******
      *******

Right Arrow Star Pattern

For more examples of the Right Arrow Star Pattern >> Click Here.

#include<stdio.h>

int main(void)
{
    int i, j, n;
    printf("Enter Right Arrow Star Pattern Rows =  ");
    scanf("%d", &n);
    
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(j < i)
                printf(" ");
            else
                printf("*");
        }
        printf("\n");
    }
    
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(j < n - i)
                printf(" ");
            else
                printf("*");
        }
        printf("\n");
    }
}

Output.

Enter Right Arrow Star Pattern Rows =  9
*********
 ********
  *******
   ******
    *****
     ****
      ***
       **
        *
       **
      ***
     ****
    *****
   ******
  *******
 ********
*********
*********

Plus (+) Star Pattern

For more examples of the + Plus Star Pattern >> Click Here.

#include<stdio.h>
int main(void)
{
    int i, j, rows;
    printf("Enter Plus Pattern Rows =  ");
    scanf("%d", &rows);
    
    for(i = 1; i <= rows * 2 - 1; i++)
    {
        if(i != rows)
        {
            for(j = 1; j <= rows; j++)
            {
                if(j == rows)
                {
                    printf("*");
                }
                printf(" ");
            }
        }
        else
        {
            for(j = 1; j <= rows * 2 - 1; j++)
            {
                printf("*");
            }
        }
        printf("\n");
    }
}

Output.

Enter Plus Pattern Rows =  8
       * 
       * 
       * 
       * 
       * 
       * 
       * 
***************
       * 
       * 
       * 
       * 
       * 
       * 
       * 

H Star Pattern

For more examples of the H Star Pattern >> Click Here.

#include <stdio.h>

int main(void)
{
    int rows, i, j, k, l;

    printf("Enter H Pattern Rows = ");
    scanf("%d", &rows);

    for (i = 1; i <= rows; i++)
    {
        for (j = 1; j <= i; j++)
        {
            printf("*");
        }
        for (k = i * 2; k <= rows * 2 - 1; k++)
        {
            printf(" ");
        }
        for (l = 1; l <= i; l++)
        {
            printf("*");
        }
        printf("\n");
    }

    for (i = 1; i <= rows - 1; i++)
    {
        for (j = rows - 1; j >= i; j--)
        {
            printf("*");
        }
        for (k = 1; k <= i * 2; k++)
        {
            printf(" ");
        }
        for (l = rows - 1; l >= i; l--)
        {
            printf("*");
        }
        printf("\n");
    }
}

Output.

Enter H Pattern Rows = 6
*          *
**        **
***      ***
****    ****
*****  *****
************
*****  *****
****    ****
***      ***
**        **
*          *

V Star Pattern

For more examples of the V Star Pattern >> Click Here.

#include <stdio.h>
void loopLogic(int rows, int i)
{
    for (int j = 1; j <= i; j++)
    {
        printf("*");
    }
}
int main(void)
{
    int rows;

    printf("Enter V Shape Star Pattern Rows = ");
    scanf("%d", &rows);

    for (int i = 1; i <= rows; i++)
    {
        loopLogic(rows, i);
        for (int k = 1; k <= 2 * (rows - i); k++)
        {
            printf(" ");
        }
        loopLogic(rows, i);
        printf("\n");
    }
}

Output.

Enter V Shape Star Pattern Rows = 9
*                *
**              **
***            ***
****          ****
*****        *****
******      ******
*******    *******
********  ********
******************

Inverted V Star Pattern

For more examples of Printing the Inverted V Star Pattern >> Click Here.

#include <stdio.h>
void loopLogic(int rows, int i)
{
    for (int j = 1; j <= i; j++)
    {
        printf("*");
    }
}
int main(void)
{
    int rows;

    printf("Enter Inverted V Shape Pattern Rows = ");
    scanf("%d", &rows);

    for (int i = rows; i >= 1; i--)
    {
        loopLogic(rows, i);
        for (int k = 1; k <= 2 * (rows - i); k++)
        {
            printf(" ");
        }
        loopLogic(rows, i);
        printf("\n");
    }
}

Output.

Enter Inverted V Shape Pattern Rows = 8
****************
*******  *******
******    ******
*****      *****
****        ****
***          ***
**            **
*              *

W Star Pattern

For more examples of the C Program to print the W Star Pattern >> Click Here.

#include <stdio.h>

void starsDisplay(int rows)
{
    for (int i = 0; i < rows; ++i)
    {
        printf("*");
    }
}
void spaceDisplay(int rows)
{
    for (int i = 0; i < rows; ++i)
    {
        printf(" ");
    }
}

int main(void)
{
    int rows;

    printf("Enter W Shape Star Pattern Rows = ");
    scanf("%d", &rows);

    for (int i = 0; i < rows; i++)
    {
        starsDisplay(i + 1);
        spaceDisplay(rows - i - 1);
        starsDisplay(rows - i + 1);
        spaceDisplay(2 * i);
        starsDisplay(rows - i);
        spaceDisplay(rows - i - 1);
        starsDisplay(i + 1);
        printf("\n");
    }
}

Output.

Enter W Shape Star Pattern Rows = 9
*        *******************        *
**       *********  ********       **
***      ********    *******      ***
****     *******      ******     ****
*****    ******        *****    *****
******   *****          ****   ******
*******  ****            ***  *******
******** ***              ** ********
***********                **********

X Star Pattern

For more examples of the X Star Pattern >> Click Here.

#include <stdio.h>

int main(void)
{
    int rows;
    printf("Enter X Pattern rows =  ");
    scanf("%d", &rows);

   int k = rows * 2 - 1;

   for(int i = 1; i <= k; i++)
   {
       for(int j = 1; j <= k; j++)
       {
           if(j == i || j == (k - i + 1))
           {
               printf("*");
           }
           printf(" ");
       }
       printf("\n");
   }
    return 0;
}

Output.

Enter X Pattern rows =  7
*            * 
 *          *  
  *        *   
   *      *    
    *    *     
     *  *      
      *       
     *  *      
    *    *     
   *      *    
  *        *   
 *          *  
*            * 

8 Star Pattern

For more examples of the 8 Star Pattern >> Click Here.

#include <stdio.h>

int main(void)
{
    int rows;
    
    printf("Enter 8 Star Pattern Rows = ");
    scanf("%d", &rows);
    
    for (int i = 1; i <= rows * 2 - 1; i++)
    {
        if (i == 1 || i == rows || i == rows * 2 - 1)
        {
            for (int j = 1; j <= rows; j++)
            {
                if (j == 1 || j == rows)
                {
                    printf(" ");
                }
                else
                {
                    printf("*");
                }
            }
        }
        else
        {
            for (int k = 1; k <= rows; k++)
            {
                if (k == 1 || k == rows)
                {
                    printf("*");
                }
                else
                {
                    printf(" ");
                }
            }
        }
        printf("\n");
    }
}

Output.

Enter 8 Star Pattern Rows = 7
 ***** 
*     *
*     *
*     *
*     *
*     *
 ***** 
*     *
*     *
*     *
*     *
*     *
 ***** 

Few more Star Pattern Programs in C