In this tutorial, we will learn and code many alphabet patterns in C programming language. However, in this tutorial, we will create a pyramid pattern using characters in C using for loop. So you may go through the following topic in C.
C Alphabet Pattern program 1: Full Pyramid Pattern of Alphabets
1 2 3 4 5 6 | Enter the no. of rows: 5 A A B A B C A B C D A B C D E |
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> void main() { int rows, i, j, k; 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 = rows - 1; j > i; j--) printf(" "); for (k = 0; k <= i; k++) printf("%c ", (char)(alphabet + k)); printf("\n"); } getch(); } |
C Alphabet Pattern program 2: Inverted Full Pyramid Pattern of Alphabets
1 2 3 4 5 6 | Enter the no. of rows: 5 A B C D E A B C D A B C A B A |
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> void main() { int rows, i, j, k; 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 (int j = 0; j <= i; j++) printf(" "); for (k = 0; k <= rows - 1 - i; k++) printf("%c ", (char)(alphabet + k)); printf("\n"); } getch(); } |
C Alphabet Pattern program 4:
Another full pyramid with a different pattern.
1 2 3 4 5 6 7 | Enter the no. of rows: 5 A B B C C C D D D D E E E E E F F F F F F |
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> void main() { int rows, i, j, k; printf("Enter the no. of rows: "); scanf("%d", &rows); // ASCII value of alphabet 'A' int alphabet = 65; for (i = 0; i <= rows; i++) { for (j = 1; j <= rows - i; j++) printf(" "); for (k = 0; k <= i; k++) printf(" %c", (char)(i + alphabet)); printf("\n"); } getch(); } |
C Alphabet Pattern program 5:
Enter the no. of rows: 5
A
B A B
C B A B C
D C B A B C D
E D C B A B C D E
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #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 = 1; j <= rows - i; j++) printf(" "); for (j = i; j > 0; j--) printf(" %c", (char)(j + 64)); for (j = 2; j <= i; j++) printf(" %c", (char)(j + 64)); printf("\n"); } } |
C Alphabet Pattern program 6:
Enter the no. of rows: 6
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #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 = 1; j <= rows - i; j++) printf(" "); for (j = 1; j <= i; j++) printf("%c", (char)(j + 64)); for (j = i - 1; j >= 1; j--) printf("%c", (char)(j + 64)); printf("\n"); } } |
C Alphabet Pattern program 7:
Enter the no. of rows: 5
A B C D E F G H I
A B C D E F G
A B C D E
A B C
A
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> void main() { int rows, i, j, l = 1, k; printf("Enter the no. of rows: "); scanf("%d", &rows); for (i = rows; i >= 1; i--) { for (j = 1; j <= l; j++) printf(" "); for (k = 1; k <= (2 *i - 1); k++) printf("%c ", 'A' + k - 1); l++; printf("\n"); } } |
C Alphabet Pattern program 8: Inverted Pyramid pattern using while loop
Enter the no. of rows: 5
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <stdio.h> void main() { int rows, i, j, l = 1, k; printf("Enter the no. of rows: "); scanf("%d", &rows); i = rows; while (i >= 1) { j = 1; while (j <= rows - i) { printf(" "); j++; } j = 1; while (j <= 2 *i - 1) { if (j <= i) { printf("%c", (char)(j + 64)); printf(" "); } else { printf("%c", (char)(2 *i - j + 64)); printf(" "); } j++; } i--; printf("\n"); } } |