Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a character pattern in C using for loop. So you may go through the following topic in C.

Pattern 1: Half Diamond pattern in c using alphabets

Enter the no. of rows: 5
A
A B
A B C
A B C D
A B C D E
A B C D
A B C
A B
A

Source Code:

#include <stdio.h>

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

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

  // ASCII value of alphabet 'A'
  int alphabet = 65;

  for (i = 0; i <= rows - 1; i++)
  {
    for (j = 0; j <= i; j++)
      printf("%c ", (char)(alphabet + j));

    printf("\n");
  }
  for (i = rows - 1; i >= 0; i--)
  {
    for (j = 0; j <= i - 1; j++)
      printf("%c ", (char)(alphabet + j));

    printf("\n");
  }

  getch();
}

Pattern 2: Half Diamond pattern in c using alphabets

Enter the no. of rows: 5
E
E D
E D C
E D C B
E D C B A
E D C B
E D C
E D
E

Source Code:

#include <stdio.h>
#include <math.h>

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

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

   for (i = rows; i >= -rows; i--)
   {
      for (j = rows-1; j >= abs(i); j--)
         printf("%c ", j + 65);

      printf("\n");
   }
}

Pattern 3: Half Diamond pattern in c using alphabets

Enter the no. of rows: 5
E
E D
E D C
E D C B
E D C B A
E D C B
E D C
E D
E

Source Code:

#include <stdio.h>
#include <math.h>

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

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

   for (i = rows; i >= -rows; i--)
   {
      for (j = rows-1; j >= abs(i); j--)
         printf("%c ", j + 65);

      printf("\n");
   }
}