Diamond Shape Star Pattern in C

In this tutorial, we will write a program for diamond patterns in C using stars. Before that, you should have knowledge on the following topic in C.


Diamond Shape Star Pattern in C

Question: C Program to Print Diamond Pattern:

#include <stdio.h>

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

  printf("Enter the no. of rows: ");
  scanf("%d", &rows);

  for (i = 0; i <= rows - 1; i++)
  {
    for (j = rows - 1; j >= i; j--)
      printf(" ");

    for (k = 0; k <= i; k++)
      printf("* ");

    printf("\n");
  }
  for (i = 0; i <= rows - 1; i++)
  {
    for (j = -1; j <= i; j++)
      printf(" ");

    for (k = 0; k <= rows - 2 - i; k++)
      printf("* ");

    printf("\n");
  }

  return 0;
}

Output:

diamons shape pattern in C