Home C Examples Star Pattern Programs in C

Star Pattern Programs in C

by Prateek Kashyap
5 minutes read

In this article, we will be discussing various star Pattern programs in C. Usually, the value of C depends on the value of number of rows and columns.

C program Pattern 1

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

C Program:

#include<stdio.h>

int main()
{
   int n;
   printf("Enter the value of N:");
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
     for(int z=n;z>i;z--)
     {
           printf(" ");
     }
     for(int j=1;j<=i*2-1;j++)
    {
   	   printf("*");
     }
   printf("\n");
   }
   for(int i=n;i>=1;i--)
   {
       for(int z=n;z>i;z--)
     {
	    printf(" ");
     }
    for(int j=1;j<=i*2-1;j++)
   {
   	   printf("*");
    }
   printf("\n");
   }
 
return 0;
}

C program Pattern 2

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

C Program:

#include<stdio.h>

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

C program Pattern 3

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

C Program:

#include<stdio.h>
int main()
{
   int n;
 
   printf("Enter the value of N:");
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
      for(int j=1;j<=i;j++)
   	{
   	    printf("*");
        }
    printf("\n");
   }
   for(int i=n;i>=1;i--)
   {
      for(int j=1;j<=i;j++)
        {
   	    printf("*");
        }
     printf("\n");
   }

return 0;
}

C program Pattern 4

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

C Program:

#include<stdio.h>

int main()
{
   int n;
   printf("Enter the value of N:");
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       for(int j=n;j>=i;j--)
   	{
   	     printf("*");
	}
       for(int z=1;z<i;z++)
       {
	    printf(" ");
       }
       for(int z=1;z<i;z++)
   	{
	    printf(" ");
        }
       for(int j=i;j<=n;j++)
   	{
   	     printf("*");
	}
       printf("\n");
   }
  for(int i=n;i>=1;i--)
   {
      for(int j=n;j>=i;j--)
       {
   	   printf("*");
       }
      for(int z=1;z<i;z++)
      {
	   printf(" ");
      }
      for(int z=1;z<i;z++)
     {
	   printf(" ");
      }
      for(int j=i;j<=n;j++)
     {
   	   printf("*");
     }
    printf("\n");
  }

return 0;
}

C program Pattern 5

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

C Program:

#include<stdio.h>

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

If you like this article on Star Pattern Programs in C .Don’t forget to Share.

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.