10 different alphabet pattern programs in C

10 different alphabet pattern programs in C:

In this post, we will learn how to print 10 different alphabet patterns in C. Let’s learn these patterns one by one:

Pattern 1:

A 
B B 
C C C 
D D D D 
E E E E E 

We will use two loops to print this pattern: one outer loop and one inner loop. The outer loop will point to each row of the pattern and the inner loop will print the characters.

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}
  • This program takes the height as an input from the user and assigns it to the height variable.
  • The for loop with i points to each row of the pattern and the for loop with j is used to print the characters.

It will print output as below:

Enter the height of the pattern: 5
A 
B B 
C C C 
D D D D 
E E E E E 

Pattern 2:

A A A A A 
B B B B 
C C C 
D D 
E 

This is similar to the above example. But the inner loop will run in reverse.

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

Output:

Enter the height of the pattern: 5
A A A A A 
B B B B 
C C C 
D D 
E 

Enter the height of the pattern: 6
A A A A A A 
B B B B B 
C C C C 
D D D 
E E 
F 

Pattern 3:

A 
A B 
A B C 
A B C D 
A B C D E 

This is similar to the first pattern. The only change is the inner loop, it will add j to A to print the current character of each row.

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

Output:

Enter the height of the pattern: 5
A 
A B 
A B C 
A B C D 
A B C D E 

Pattern 4:

A B C D E 
A B C D 
A B C 
A B 
A 

This is the reverse pattern of pattern 3. We need to change the inner loop to print it:

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

Output:

Enter the height of the pattern: 5
A B C D E 
A B C D 
A B C 
A B 
A 

Enter the height of the pattern: 6
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 

Pattern 5:

A 
B A 
C B A 
D C B A 
E D C B A 

Below program prints this:

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

It will print:

Enter the height of the pattern: 5
A 
B A 
C B A 
D C B A 
E D C B A 

Pattern 6:

G F E D C B A 
F E D C B A 
E D C B A 
D C B A 
C B A 
B A 
A 

It is the reverse pattern of pattern 5. The below program prints this:

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

Output:

Enter the height of the pattern: 7
G F E D C B A 
F E D C B A 
E D C B A 
D C B A 
C B A 
B A 
A 

Pattern 7:

A 
B C 
D E F 
G H I J 
K L M N O

The characters are changing continuously in this pattern. So, we will use a separate character variable to hold the current character to print.

#include <stdio.h>

int main()
{
	int height;
	char c = 'A';

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

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

	return 0;
}

Output:

Enter the height of the pattern: 5
A 
B C 
D E F 
G H I J 
K L M N O 

Pattern 8:

A 
B G 
C H L 
D I M P 
E J N Q S 
F K O R T U 

The below program prints this pattern:

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

	for (int i = 0; i < height; i++)
	{
		int diff = height - 1;
		int c = i;

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

	return 0;
}

Output:

Enter the height of the pattern: 6
A 
B G 
C H L 
D I M P 
E J N Q S 
F K O R T U 

Pattern 9:

        A 
      A B A 
    A B C B A 
  A B C D C B A 
A B C D E D C B A 

The below C program can print this pattern for different heights:

#include <stdio.h>

int main()
{
	int height;

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

	for (int i = 1; i <= height; i++)
	{
		for (int j = 0; j < height - i; j++)
		{
			printf("  ");
		}

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

	return 0;
}

C character pattern example

Pattern 10:

A 
B C 
C D E 
D E F G 
E F G H I 

For this pattern, we will store the starting character of each row in a different variable. Then we will assign it to a temporary variable and use it to print the row characters. At the end of each row print, it will be incremented by 1 to change.

#include <stdio.h>

int main()
{
	int height;
	char c = 'A';

	printf("Enter the height of the pattern: ");
	scanf("%d", &height);

	for (int i = 0; i < height; i++)
	{
		char charToPrint = c;
		for (int j = 0; j <= i; j++)
		{
			printf("%c ", charToPrint);
			charToPrint++;
		}
		c++;
		printf("\n");
	}

	return 0;
}

Output:

Enter the height of the pattern: 5
A 
B C 
C D E 
D E F G 
E F G H I 

Enter the height of the pattern: 8
A 
B C 
C D E 
D E F G 
E F G H I 
F G H I J K 
G H I J K L M 
H I J K L M N O 

You might also like: