Print alphabetic pattern in C: In c we can build various pyramids or patterns with numbers, alphabets or stars etc.

Program – 1

Implement the following alphabet pattern in C

A
BC
DEF

Program for alphabet pattern

#include <stdio.h>

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

char c;

printf("Enter number of character till you want pyramid:");
scanf("%d",&n);
c='A';
for(i=0;i<n;i++)
{
  for(j=0;j<=i;j++)
  {
    if(c=='Z')
      c='A';
    printf("%c",c);
    c++;
   }
  printf("\n");
}

    return 0;
}

Output :
alphabet pyramid program in c

Program – 2

Implement the following alphabet pattern in C.
A
AB
ABC
ABCD
ABCDE
ABCDE
ABCD
ABC
AB
A

Program for alphabet pattern

#include <stdio.h>

int main()
{
int x,y;

static char str[]="ABCDE";

for(x=0;x<5;x++)

{

y=x+1;

printf("%-5.*s\n",y,str);

}

for(x=4;x>=0;x--)

{

y=x+1;

printf("%-5.*s\n",y,str);

}

    return 0;
}

Output:
alphabet pyramid program in c

Program – 3

Implement the following diamond shape alphabet pyramid
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A

Pyramid program in C

#include <stdio.h>

int main()
{
char c,r,ch;

int sp;

printf("Enter any character:");

scanf("%c",&ch);

if(ch>='a' && ch<= 'z')

ch=ch-32;

printf("\n");

for(r='A' ; r<=ch; r++)

{

for(sp=ch-r;sp>=1;sp--)

printf(" ");

for(c='A';c<=r;c++)

printf("%c",c);

for(c=r-1;c>='A';c--)

printf("%c",c);

printf("\n");

}

for(r='A' ; r<=ch;ch--, r++)

{

for(sp=r;sp>='A';sp--)

printf(" ");

for(c='A';c<=ch-1;c++)

printf("%c",c);

for(c=ch-2;c>='A';c--)

printf("%c",c);

printf("\n");

}

    return 0;
}

OutPut :

Print alphabetic pattern in C

Write A Comment