C Program to Generate Diamond Pattern Using Stars
Generating diamond shape pattern made up of stars in C programming language.
Diamond Pattern C Program
#include<stdio.h>
int main()
{
int i, n, j;
printf("Enter number of lines: ");
scanf("%d", &n);
/* Upper part of diamond */
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
/* Lower part of diamond patter */
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output of Above Program
Enter number of lines: 10 * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ***************** *************** ************* *********** ********* ******* ***** *** *