Half Diamond Star Pattern in C

We will write two different patterns diamond shape programs in C. So you may go through the following topic in C first.

1. Right half diamond pattern in C

#include <stdio.h>

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

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

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

    printf("\n");
  }

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

    printf("\n");
  }

  return 0;
}

Enter the no. of rows: 5
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*


2. Left half diamond pattern in C

#include <stdio.h>

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

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

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

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

    printf("\n");
  }

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

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

    printf("\n");
  }

  return 0;
}
Enter the no. of rows: 5
    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *