Skip to content
Home » Pattern Program 22 in C

Pattern Program 22 in C

Learn about Pattern Program 22 in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Pattern Program 22 in C

To print a pattern as given below the follow the below C code by entering the number of lines you want.

For 5 lines the patter looks like:

ABCDEFGFEDCBA
ABCDE   EDCBA
ABCD     DCBA
ABC       CBA
AB         BA
A           A

Source code:

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

  printf("Enter number of lines: ");
  scanf("%d",&n);

  for(int i=0; i<=n; i++)
  {
    ch = 'A';
    for(int j=0; j<=n-i; j++, ch++)
    {
      printf("%c",ch);
    }

    if(i==0)
    {
      printf("%c",ch);
    }
    else
    {
      for(int k=0; k<(2*i)+1; k++){
        printf(" ");
      }
    }

    ch--;
    for(int j=0; j<=n-i; j++, ch--)
    {
      printf("%c",ch);
    }

    printf("\n");
  }
  return 0;
}

Output:

Enter number of lines: 5
ABCDEFGFEDCBA
ABCDE   EDCBA
ABCD     DCBA
ABC       CBA
AB         BA
A           A

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

Similar Codes :
Pattern Program 21 in C
Pattern Program in C for Inverted Full Pyramid