Star Program In C

Square Star Pattern

The code provided below generates a pattern of stars in a square shape:

Example

#include <stdio.h>
 int main()
{
    int n;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            printf("*");
        }
        printf("\n");
    }
    
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Square Star Pattern

Now, we generate the empty square asterisk design. Below is the code snippet for producing this specific pattern:

Example

int main()
{
    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(i==1 ||i==n||j==1||j==n)
            {
            printf("*");
            }
            else
            printf(" ");
        }
        printf("\n");
    }
    
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Square Pattern with Diagonal

The code snippet for generating a hollow square star pattern is presented here:

Example

#include <stdio.h>
int main()
{
    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(i==1 ||i==n||j==1||j==n-i+1||i==j||j==n)
            {
            printf("*");
            }
            else
            {
                
                      printf(" ");
                  }
               
            }      
        printf("\n");
    }
    
    return 0;
}

Output

Output

Enter the number of rows*

Rhombus Star Pattern

The code to generate a rhombus star pattern is presented here:

Example

#include <stdio.h>

int main()
{
    int n;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=i-1;j++)
        {
            printf(" ");
        }
        for(int k=1;k<=n;k++)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Rhombus Star Pattern

The code to generate a hollow rhombus star pattern is provided below:

Example

#include <stdio.h>

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

Output

Output

Enter the number of rows*

Mirrored Rhombus Star Pattern

The code provided below generates a mirrored rhombus star pattern:

Example

#include <stdio.h>
int main()
{
    int n;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            printf(" ");
        }
        for(int k=1;k<=n;k++)
        {
           printf("*");
            
        }
        printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Mirrored Rhombus Star Pattern

The code provided below generates a hollow mirrored rhombus star pattern:

Example

#include <stdio.h>
int main()
{
    int n;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            printf(" ");
        }
        for(int k=1;k<=n;k++)
        {
         if(i==1 || i==n || k==1 || k==n)
           printf("*");
            else
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Right Triangle Star Pattern

The code provided below demonstrates the implementation of a right triangle star pattern:

Example

#include <stdio.h>

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

Output

Output

Enter the number of rows*

Hollow Right Triangle Star Pattern

The code snippet for generating a hollow right triangle star pattern is presented below:

Example

#include <stdio.h>

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

Output

Output

Enter the number of rows*

Mirrored Right Triangle Star Pattern

The code provided below demonstrates the implementation of a right triangle star pattern that is mirrored:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=i-1;j++)
        {
          printf(" ");
        }
        for(int k=1;k<=m;k++)
        {
            printf("*");
        }
        printf("\n");
        m++;
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Mirrored Right Triangle Star Pattern

The code provided below demonstrates how to create a hollow mirrored right triangle star pattern:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=i-1;j++)
        {
          printf(" ");
        }
        for(int k=1;k<=m;k++)
        {
           if(k==1 || k==m || m==n)
            printf("*");
            else
            printf(" ");
        }
        printf("\n");
        m++;
    }
    return 0;
}

Output

Output

Enter the number of rows*

Inverted Right Triangle Star Pattern

The code provided below generates an inverted right triangle star pattern:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
      for(int j=1;j<=i;j++)
      {
          printf("*");
      }
      printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Inverted Right Triangle Star Pattern

The code provided below generates a hollow inverted right triangle star pattern:

Example

#include <stdio.h>

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

Output

Output

Enter the number of rows*

Inverted Mirrored Right Triangle Star Pattern

The code provided below is for generating an inverted mirrored right triangle star pattern:

Example

#include <stdio.h>

int main()
{
    int n,m;
    printf("Enter the number of rows");
    scanf("%d",&n);
    m=n;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<i;j++)
       {
           printf(" ");
       }
       for(int k=1;k<=m;k++)
       {
           printf("*");
       }
       m--;
   
      printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Inverted Mirrored Right Triangle Star Pattern

The code provided below generates a hollow inverted mirrored right triangle star pattern:

Example

#include <stdio.h>

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

Output

Output

Enter the number of rows*

Pyramid Star Pattern

The code snippet for generating a pyramid star pattern is provided below:

Example

#include <stdio.h>
int main()
{
    int n,m;
    printf("Enter the number of rows");
    scanf("%d",&n);
    m=n;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m-1;j++)
       {
           printf(" ");
       }
       for(int k=1;k<=2*i-1;k++)
       {
         printf("*");
       }
       m--;
   
      printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Hollow Pyramid Star Pattern

The code provided below generates a hollow pyramid pattern using asterisks:

Example

#include <stdio.h>

int main()
{
    int n,m;
    printf("Enter the number of rows");
    scanf("%d",&n);
    m=n;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m-1;j++)
       {
           printf(" ");
       }
       for(int k=1;k<=2*i-1;k++)
       {
          if(k==1 || k==2*i-1 || i==n)
         printf("*");
         else
         printf(" ");
       }
       m--;
   
      printf("\n");
    }
    return 0;
}

Output

Output

Enter the number of rows*

Inverted Pyramid Star Pattern

The code for the inverted pyramid is given below:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of rows");
    scanf("%d",&n);

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

Output

Output

Enter the number of rows*

Hollow Pyramid Star Pattern

The code to generate a hollow pyramid star pattern is presented here:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of rows");
    scanf("%d",&n);

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

Output

Output

Enter the number of rows*

Half Diamond Star Pattern

The code snippet for generating a half diamond star pattern is provided below:

Example

#include <stdio.h>

int main()
{
    int n,m=1;
    printf("Enter the number of columns");
    scanf("%d",&n);
for(int i=1;i<=n;i++)
{
  for(int j=1;j<=i;j++)
  {
    printf("*");
  }
  printf("\n");
}
 for(int i=n-1;i>=1;i--)
 {
   for(int j=1;j<=i;j++)
   {
     printf("*");
   }
   printf("\n");
 }  
   
    return 0;
}

Output

Output

Enter the number of rows*

Diamond Star Pattern

The code snippet for generating the diamond star pattern is presented here:

Example

#include <stdio.h>
int main(void) {
  int n;
  printf("Enter the number of rows\n");
  scanf("%d",&n);
  int spaces=n-1;
  int stars=1;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=spaces;j++)
    {
      printf(" ");
    }
    for(int k=1;k<=stars;k++)
    {
      printf("*");
    }
    if(spaces>i)
    {
      spaces=spaces-1;
      stars=stars+2;
    }
    if(spaces<i)
    {
      spaces=spaces+1;
      stars=stars-2;
    }
    printf("\n");
  }
  return 0;}

Output

Output

Enter the number of rows*

Right Arrow Star Pattern

The code for generating a right arrow star pattern is provided below:

Example

#include <stdio.h>

int main(void) {
  
  int n;
  printf("Enter the number of columns");
  scanf("%d",&n);
  //printing the upper part of the pattern..
 for(int i=0;i<n;i++)
 {
   for(int j=0;j<i;j++)
   {
       printf(" ");
   }
   for(int k=1;k<=n-i;k++)
   {
     printf("*");
   }
   printf("\n");
 }
for(int i=1;i<n;i++)
{
  for(int j=1;j<n-i;j++)
  {
    printf(" ");
  }
  for(int k=1;k<=i+1;k++)
  {
    printf("*");
  }
  printf("\n");
}
  return 0;
}

Output

Output

Enter the number of rows*

Left Arrow Star Pattern

The code provided below demonstrates how to create a pattern resembling a left arrow using stars:

Example

#include <stdio.h>

int main(void) {
  
  int n;
  printf("Enter the number of columns");
  scanf("%d",&n);
  //printing the upper part of the pattern..
 for(int i=1;i<=n;i++)
 {
   for(int j=1;j<=n-i;j++)
   {
       printf(" ");
   }
   for(int k=0;k<=n-i;k++)
   {
     printf("*");
   }
   printf("\n");
 }
for(int i=1;i<n;i++)
{
  for(int j=1;j<i+1;j++)
  {
    printf(" ");
  }
  for(int k=1;k<=i+1;k++)
  {
    printf("*");
  }
  printf("\n");
}
  return 0;
}

Output

Output

Enter the number of rows*

Plus Star Pattern

The code for the plus star pattern is given below:

Example

#include <stdio.h>

int main(void) {
  int n;
  printf("Enter the odd number only");
  scanf("%d", &n);
  for(int i=1;i<=n;i++)
  {
    if(i==((n/2)+1))
    {
      for(int j=1;j<=n;j++)
      {
        printf("+");
      }
 
    }
    else
    {
    for(int j=1;j<=n/2;j++)
    {
      printf(" ");
    }
    printf("+");
    }
    printf("\n");
  }
  return 0;
}

Output

Output

Enter the number of rows*

X Star Pattern

The code for the X star pattern is given below:

Example

#include <stdio.h>

int main(void) {
  int n,m;
  printf("Enter the number");
  scanf("%d",&n);
  m=2*n-1;
  for(int i=1;i<=m;i++)
  {
    for(int j=1;j<=m;j++)
    {
       if(i==j || j==(m-i+1))
       {
         printf("*");
       }
       else
       {
         printf(" ");
       }
    }
    printf("\n");
  }
  return 0;
}

Output

Input Required

This code uses input(). Please provide values below: