Skip to content
Home » C program to print full diamond of spaces and stars

C program to print full diamond of spaces and stars

Learn about C program to print full diamond of spaces and stars in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to print full diamond of spaces and stars

To print the below given pattern then follow the below given C program.

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

Program:

#include<stdio.h> 
int main()
{
   int n;

   printf("Enter value of n: ");
   scanf("%d",&n);
   
   for(int i=1; i <= n; i++)
   {
     for(int j=i; j <= n; j++)
     {
        printf("*");
     }

     for(int k=1; k < 2*i-1; k++)
     {
        printf(" ");
     }

     for(int l=i; l <= n; l++)
     {
        printf("*");
     }
     printf("\n");
  }

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

   return 0;
}

Output:

Enter value of n: 4
********
***  ***
**    **
*      *
**    **
***  ***
********

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to print full diamond of stars
C program to print half diamond of numbers