In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in C.
Pattern 1: C program for character/alphabet.
Enter the no. of rows: 6
F F F F F F
E E E E E
D D D D
C C C
B B
A
Source code:
#include <stdio.h>
void main()
{
int i, j, rows;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = i; j <= rows; j++)
printf("%c ", (char)(i + 64));
printf("\n");
}
}
Pattern 2: C program for character/alphabet.
Enter the no. of rows: 5
A A A A A
B B B B
C C C
D D
E
Source code:
#include <stdio.h>
void main()
{
int i, j, rows;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; i--)
{
for (j = 1; j <= i; j++)
printf("%c ", (char)(i + 64));
printf("\n");
}
}
Pattern 3: C program for character/alphabet.
Enter the no. of rows: 5
A B C D E
A B C D
A B C
A B
A
Source code:
#include <stdio.h>
void main()
{
int i, j, rows;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= rows - i + 1; j++)
printf("%c ", (char)(j + 64));
printf("\n");
}
}
Pattern 4: C program for character/alphabet.
Enter the no. of rows: 5
E D C B A
D C B A
C B A
B A
A
Source code:
#include <stdio.h>
void main()
{
int i, j, rows;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; i--)
{
for (j = i; j >= 1; j--)
printf("%c ", (char)(j + 64));
printf("\n");
}
}
Pattern 5: C program for character/alphabet.
Enter the no. of rows: 5
E F G H I
D E F G
C D E
B C
A
Source code:
#include <stdio.h>
void main()
{
int rows, k, i, j;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; i--)
{
k = i;
for (j = 1; j <= i; j++, k++)
printf("%c ", (char)(k + 64));
printf("\n");
}
}
Pattern 6: C program for character/alphabet.
Enter the no. of rows: 5
E D C B A
E D C B
E D C
E D
E
Source code:
#include <stdio.h>
void main()
{
int rows, i, j;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = rows; j >= i; j--)
printf("%c ", (char)(j + 64));
printf("\n");
}
}
Pattern 7: C program for character/alphabet.
Enter the no. of rows: 5
A B C D E
B C D E
C D E
D E
E
Source code:
#include<stdio.h>
void main()
{
int rows, i, j;
printf("Enter the no. of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; i++)
{
for(j=i; j<=rows; j++)
printf("%c ",(char)(j+64));
printf("\n");
}
}