Pattern Program In C++
In this article, you will learn to create 30 different Pattern program in C++. Steps to create patterns are explained with the code.
- Square pattern in C++
- Hollow square pattern
- Left triangle Pattern program in C++
- Right triangle Pattern program in C++
- Left Down triangle
- Right Down triangle
- Hollow triangle star pattern in C++
- Pyramid star pattern in C++
- Reverse pyramid star pattern in C++
- Hollow pyramid star pattern in C++
- Diamond star pattern in C++
- Hollow Diamond star pattern in C++
- Hourglass star pattern
- Right Pascal star pattern
- Left Pascal star pattern
- Heart star pattern
- Plus star pattern
- Cross star pattern
- Left triangle number pattern
- Right triangle number pattern
- Number pyramid pattern
- Number pyramid reverse pattern
- Hollow number pyramid pattern
- Number diamond pattern
- Hollow number diamond pattern
- Alphabet pyramid pattern
- Reverse alphabet pyramid pattern
- Hollow alphabet pyramid pattern
- Alphabet diamond pattern
- Hollow alphabet diamond pattern
Table Of Contents
1. Square pattern in C++
The most straightforward pattern that you can start with is a square pattern in C++.
***** ***** ***** ***** *****
It is a pattern that has a shape of square or rectangle.
Here are the steps to create the square pattern in C++:
- Take a size of the square (you can also take user input).
- Now create a nested loop where the external loop runs to the print column and the inner loop runs to the print row.
- Print star in the internal loop using
cout << "*"
command.
#include <iostream>
using namespace std;
int main() {
// size of the square
int size = 5;
// outer loop
for (int i = 0; i < size; i++) {
// inner loop
for (int j = 0; j < size; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
***** ***** ***** ***** *****
2. Hollow Square pattern in C++
The hollow square is the same as the square pattern but has stars only at the boundaries.
***** * * * * * * *****
Following are the steps to create a hollow square pattern in C++:
- Take the size of the square.
- Create a nested loop where there are 2 loops in the external loop.
- In the first internal loop, the spaces and second internal loop prints the star.
- Break the line after completing both internal loops to create a new line.
#include <iostream>
using namespace std;
int main() {
// size of the square
int size = 5;
// outer loop
for (int i = 0; i < size; i++) {
// inner loop
for (int j = 0; j < size; j++) {
// print only star in first and last row
if (i == 0 || i == size - 1) {
cout << "*";
}
else {
// print star only at first and last position row
if (j == 0 || j == size - 1) {
cout << "*";
}
else {
cout << " ";
}
}
}
cout << "\n";
}
return 0;
}
Output:
***** * * * * * * *****
3. Left triangle star pattern in C++
The left triangle star pattern is a triangle with its perpendicular line on the left side.
* ** *** **** *****
Following are the steps to create a left triangle star pattern in C++:
- Set the size of your triangle.
- Create a nested loop with 1 internal loop that will print stars in the row.
- Use cout << "\n" to break the line at the end of the internal loop.
- The internal loop will run the number of times as the external loop has run.
#include <iostream>
using namespace std;
int main() {
// size of the triangle
int size = 5;
// loop to print the pattern
for (int i = 0; i < size; i++) {
// print column
for (int j = 0; j <= i; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* ** *** **** *****
4. Right triangle C++ pattern program
The right triangle star pattern in C++ is also a triangle pattern but it is perpendicular to the left side.
* ** *** **** *****
While creating this you have to deal with both spaces and stars you can see the pattern above.
Here are the steps to create a right triangle star pattern in C++:
- Create an external loop that has 2 internal loops, one will print spaces and the other will print stars.
- Inside the first internal loop, print the space for the number of times as the size of triangle minus for the times the external loop has run.
- In the second internal loop print, the star for a number of times the external loop has run.
- Break the line after the end of both internal loops.
#include <iostream>
using namespace std;
int main() {
// size of the triangle
int size = 5;
// loop to print the pattern
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 1; j < size - i; j++) {
cout << " ";
}
// print stars
for (int k = 0; k <= i; k++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* ** *** **** *****
5. Left Down Triangle
The left down triangle looks like water image of left triangle star pattern.
***** **** *** ** *
The steps to create a downward triangle C++ pattern program is as follows:
- Decide the size of the triangle.
- Create a nested loop where the internal loop print star for times equal to size minus the outer loop index.
- Break the line after the end of the inner loop using
cout << "\n"
.
#include <iostream>
using namespace std;
int main() {
// size of the triangle
int size = 5;
for (int i = 0; i < size; i++) {
// print stars
for (int j = 0; j < size - i; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
***** **** *** ** *
6. Right Down Triangle
The right down triangle looks like the water image of the right triangle star pattern.
***** **** *** ** *
The complete code of the downward triangle star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// size of the triangle
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// print stars
for (int j = size; j > i; j--) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
***** **** *** ** *
7. Hollow triangle star pattern in C++
The hollow triangle star pattern in C++ is a left triangle pattern that is hollow from the inside.
* ** * * * * * * ******
Here are the steps for the hollow triangle star pattern in C++:
- First, take the size of the hollow triangle.
- Create a nested loop with 1 inner loop.
- Inside the inner loop, check if it is the first or the last row of the triangle then only print stars, if not check if it is the first or last position of the row then again print star, if not print space.
- Change line after each row using
cout << "\n"
.
#include <iostream>
using namespace std;
int main() {
// size of the triangle
int size = 5;
for (int i = 1; i <= size; i++) {
for (int j = 0; j < i; j++) {
// not last row
if (i != size) {
if (j == 0 || j == i - 1) {
cout << "*";
} else {
cout << " ";
}
}
// last row
else {
cout << "*";
}
}
cout << "\n";
}
return 0;
}
Output:
* ** * * * * * * ******
8. Pyramid star pattern in C++
The pyramid pattern in C++ is the most famous pattern program.
* *** ***** ******* *********
The steps to create a pyramid pattern in C++ are given below.
- Take the size and start with creating an external loop to print the rows.
- We have to manage spaces before printing stars so the external loop has 2 internal loops first to print spaces and second to print stars.
- Within first internal loop print number of spaces equal to the size of pyramid minus the outer loop index.
- Inside the second inner loop, print the stars for the number of times equal to 2 multiplied by the outer loop index minus 1.
- At the end of both inner loops print a new line.
#include <iostream>
using namespace std;
int main() {
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print stars
for (int k = 0; k < 2 * i + 1; k++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* *** ***** ******* *********
9. Reverse pyramid star pattern in C++
********* ******* ***** *** *
The reverse pyramid star pattern in C++ looks like the water image of the pyramid star pattern.
Following the same steps as above and changing the order of steps, we get the reverse pyramid.
#include <iostream>
using namespace std;
int main() {
// size of the pyramid
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// print stars
for (int k = 0; k < 2 * (size - i) - 1; k++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
********* ******* ***** *** *
10. Hollow pyramid pattern in C++
The hollow pyramid is another pyramid type that is hollow from the inside.
* * * * * * * *********
Following are the steps to create a Hollow pyramid star pattern in C++:
- Take the size of your pattern to start with.
- The first internal loop will print the first set of spaces for the number of times as the size of the pyramid minus the outer loop index.
- The second internal loop will print the stars if it is first of the last row then print only stars, if not then check if it is first or the last position of the row then print star, if not print space.
- Keep changing line after each row using
cout << "\n"
.
#include <iostream>
using namespace std;
int main() {
// size of the pyramid
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print stars
for (int k = 0; k < 2 * i + 1; k++) {
if (i == 0 || i == size - 1) {
cout << "*";
}
else {
if (k == 0 || k == 2 * i) {
cout << "*";
}
else {
cout << " ";
}
}
}
cout << "\n";
}
return 0;
}
Output:
* * * * * * * *********
11. Diamond star pattern in C++
Given below is the diamond star pattern. Its first half looks like a pyramid and the other half looks like a reverse pyramid pattern.
* *** ***** ******* ********* ******* ***** *** *
The complete code to create diamond shaped star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing star
for (int k = 0; k < i * 2 - 1; k++) {
cout << "*";
}
cout << "\n";
}
// downside pyramid
for (int i = 1; i <= size - 1; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing star
for (int k = (size - i) * 2 - 1; k > 0; k--) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* *** ***** ******* ********* ******* ***** *** *
12. Hollow diamond star pattern in C++
The hollow diamond pattern has a shape of a diamond star pattern but hollow inside.
* * * * * * * * * * * * * * * *
The complete code to create a hollow diamond star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing star
for (int k = 0; k < i * 2 - 1; k++) {
if (k == 0 || k == 2 * i - 2) {
cout << "*";
}
else {
cout << " ";
}
}
cout << "\n";
}
// downside triangle
for (int i = 1; i < size; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing star
for (int k = (size - i) * 2 - 1; k >= 1; k--) {
if (k == 1 || k == (size - i) * 2 - 1) {
cout << "*";
}
else {
cout << " ";
}
}
cout << "\n";
}
return 0;
}
Output:
* * * * * * * * * * * * * * * *
13. Hourglass star pattern in C++
Given below is the hourglass pattern. Its first half looks like a reverse pyramid and the other half looks like a pyramid.
********* ******* ***** *** * *** ***** ******* *********
The complete code to create an hourglass star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
// reversed pyramid star pattern
for (int i = 0; i < size; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing star
for (int k = 0; k < (size - i) * 2 - 1; k++) {
cout << "*";
}
cout << "\n";
}
// pyramid star pattern
for (int i = 2; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing star
for (int k = 0; k < i * 2 - 1; k++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
********* ******* ***** *** * *** ***** ******* *********
14. Right pascal star pattern
Given below is the right pascal star pattern.
* ** *** **** ***** **** *** ** *
Looking at the pattern you can observe that it combines the right triangle star pattern and reversed triangle star pattern together. The code for the right pascal star pattern in C++ is below.
#include <iostream>
using namespace std;
int main() {
// right pasal triangle
int size = 5;
for (int i = 1; i <= size; i++) {
for (int j = 0; j < i; j++) {
cout << "*";
}
cout << "\n";
}
for (int i = 1; i <= size - 1; i++) {
for (int j = 0; j < size - i; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* ** *** **** ***** **** *** ** *
15. Left pascal star pattern
Given below is the left pascal star pattern.
* ** *** **** ***** **** *** ** *
The complete code for the left pascal star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// left pasal triangle
int size = 5;
for (int i = 1; i <= size; i++) {
for (int j = 0; j < size - i; j++) {
cout << " ";
}
for (int k = 0; k < i; k++) {
cout << "*";
}
cout << "\n";
}
for (int i = 1; i <= size - 1; i++) {
for (int j = 0; j < i; j++) {
cout << " ";
}
for (int k = 0; k < size - i; k++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
* ** *** **** ***** **** *** ** *
16. Heart pattern
*** *** ***** ***** *********** ********* ******* ***** *** *
The Heart star pattern in C++ is a very complex pattern.
The complete code for the heart star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// heart star pattern
int size = 6;
for (int i = size / 2; i < size; i += 2) {
// print first spaces
for (int j = 1; j < size - i; j += 2) {
cout << " ";
}
// print first stars
for (int j = 1; j < i + 1; j++) {
cout << "*";
}
// print second spaces
for (int j = 1; j < size - i + 1; j++) {
cout << " ";
}
// print second stars
for (int j = 1; j < i + 1; j++) {
cout << "*";
}
cout << "\n";
}
// lower part
// inverted pyramid
for (int i = size; i > 0; i--) {
for (int j = 0; j < size - i; j++) {
cout << " ";
}
for (int j = 1; j < i * 2; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}
Output:
*** *** ***** ***** *********** ********* ******* ***** *** *
17. Plus star pattern in C++
Given below is plus pattern. It has the shape of the mathematical plus sign(+).
* * ***** * *
The complete code for the plus star pattern in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// size of plus, use odd number
int size = 5;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
// print only stars in middle row
if (i == size / 2) {
cout << "*";
}
// other than middle row, print star only at index size/2
else {
if (j == size / 2) {
cout << "*";
} else {
cout << " ";
}
}
}
cout << "\n";
}
return 0;
}
Output:
* * ***** * *
18. Cross pattern program in C++
Given below is the cross pattern has the shape of the mathematical cross sign (X).
* * * * * * * * *
The complete code for the cross pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// size of cross, use odd number
int size = 5;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if (i==j || i+j==size-1) {
cout << "*";
} else {
cout << " ";
}
}
cout << "\n";
}
return 0;
}
Output:
* * * * * * * * *
Up to now we have covered 18 star patterns in C++ now let's see some number patterns.
19. Left triangle number pattern
1 12 123 1234 12345
The complete code for the left triangle number pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
// loop to print the pattern
for (int i = 0; i < size; i++) {
// print column
for (int j = 0; j <= i; j++) {
cout << (j+1);
}
cout << "\n";
}
return 0;
}
Output:
1 12 123 1234 12345
20. Right triangle number pattern
1 12 123 1234 12345
The complete code for the right triangle number pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
// loop to print the pattern
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 1; j < size - i; j++) {
cout << " ";
}
// print number
for (int k = 0; k <= i; k++) {
cout << (k+1);
}
cout << "\n";
}
return 0;
}
Output:
1 12 123 1234 12345
21. Number pyramid pattern
The number pyramid pattern has the shape of the pyramid and are made up of numbers.
1 123 12345 1234567 123456789
The complete code for the number pyramid pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print number
for (int k = 0; k < 2 * i + 1; k++) {
cout << (k+1);
}
cout << "\n";
}
return 0;
}
Output:
1 123 12345 1234567 123456789
22. Number pyramid reverse pattern
The number pyramid reverse pattern is a reverse pyramid pattern made up of numbers.
123456789 1234567 12345 123 1
The complete code for the number pyramid reverse pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// print number
for (int k = 0; k < 2 * (size - i) - 1; k++) {
cout << (k+1);
}
cout << "\n";
}
return 0;
}
Output:
123456789 1234567 12345 123 1
23. Hollow number pyramid pattern
The hollow number pyramid pattern is hollow pyramid pattern made up of numbers.
1 1 2 1 2 1 2 123456789
The complete code for the hollow number pyramid pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print number
int num = 1;
for (int k = 0; k < 2 * i + 1; k++) {
if (i == 0 || i == size - 1) {
cout << num++;
} else {
if (k == 0 || k == 2 * i) {
cout << num++;
} else {
cout << " ";
}
}
}
cout << "\n";
}
return 0;
}
Output:
1 1 2 1 2 1 2 123456789
24. Number diamond pattern
The number diamond pattern is a diamond pattern made up of numbers.
1 123 12345 1234567 123456789 1234567 12345 123 1
The complete code for the number diamond pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
int num = 1;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing number
for (int k = 0; k < i * 2 - 1; k++) {
cout << num++;
}
// set the number to 1
num = 1;
cout << "\n";
}
// downside pyramid
for (int i = 1; i <= size - 1; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing number
for (int k = (size - i) * 2 - 1; k > 0; k--) {
cout << num++;
}
// set num to 1
num = 1;
cout << "\n";
}
return 0;
}
Output:
1 123 12345 1234567 123456789 1234567 12345 123 1
25. Hollow number diamond pattern
The hollow number diamond pattern is hollow diamond pattern made up of numbers.
1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
The complete code for the hollow number diamond pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5, num = 1;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing number
for (int k = 0; k < i * 2 - 1; k++) {
if (k == 0 || k == 2 * i - 2) {
cout << num++;
} else {
cout << " ";
}
}
// set the number to 1
num = 1;
cout << "\n";
}
// downside triangle
for (int i = 1; i < size; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing number
for (int k = (size - i) * 2 - 1; k >= 1; k--) {
if (k == 1 || k == (size - i) * 2 - 1) {
cout << num++;
} else {
cout << " ";
}
}
// set the number to 1
num = 1;
cout << "\n";
}
return 0;
}
Output:
1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
Let's now create some alphabet patterns in C++.
26. Alphabet pyramid pattern
The alphabet pyramid pattern is a pyramid pattern made up of alphabet.
A ABC ABCDE ABCDEFG ABCDEFGHI
The complete code for the alphabet pyramid pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5, alpha = 65;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print alphabets
for (int k = 0; k < 2 * i + 1; k++) {
cout << ((char)(alpha+k));
}
cout << "\n";
}
return 0;
}
Output:
A ABC ABCDE ABCDEFG ABCDEFGHI
27. Reverse alphabet pyramid pattern
The reverse alphabet pyramid pattern is a pyramid pattern made up of the alphabet.
ABCDEFGHI ABCDEFG ABCDE ABC A
The complete code for the reverse alphabet pyramid pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
// size of the square
int size = 5, alpha = 65;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// print alphabets
for (int k = 0; k < 2 * (size - i) - 1; k++) {
cout << ((char) (alpha + k));
}
cout << "\n";
}
return 0;
}
Output:
ABCDEFGHI ABCDEFG ABCDE ABC A
28. Hollow alphabet pyramid pattern
The hollow alphabet pyramid pattern is a hollow pyramid pattern made up of the alphabet.
A B C D E F G HIJKLMNOP
The complete code for the hollow alphabet pyramid pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5, alpha = 65, num = 0;
for (int i = 0; i < size; i++) {
// print spaces
for (int j = 0; j < size - i - 1; j++) {
cout << " ";
}
// print alphabets
for (int k = 0; k < 2 * i + 1; k++) {
if (i == 0 || i == size - 1) {
cout << ((char)(alpha+num++));
} else {
if (k == 0 || k == 2 * i) {
cout << ((char)(alpha + num++));
} else {
cout << " ";
}
}
}
cout << "\n";
}
return 0;
}
Output:
A B C D E F G HIJKLMNOP
29. Alphabet diamond pattern
The alphabet diamond pattern is a diamond pattern made up of the alphabet.
A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFG ABCDE ABC A
The complete code for the alphabet diamond pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
int alpha = 65;
int num = 0;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing alphabets
for (int k = 0; k < i * 2 - 1; k++) {
cout << ((char)(alpha+num++));
}
// set the number to 0
num = 0;
cout << "\n";
}
// downside pyramid
for (int i = 1; i <= size - 1; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing alphabets
for (int k = (size - i) * 2 - 1; k > 0; k--) {
cout << ((char)(alpha+num++));
}
// set num to 0
num = 0;
cout << "\n";
}
return 0;
}
Output:
A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFG ABCDE ABC A
30. Hollow alphabet diamond pattern
The hollow alphabet diamond pattern is a hollow diamond pattern made up of the alphabet.
A A B A B A B A B A B A B A B A
The complete code for the hollow alphabet diamond pattern program in C++ is given below.
#include <iostream>
using namespace std;
int main() {
int size = 5;
int alpha = 65;
int num = 0;
// upside pyramid
for (int i = 1; i <= size; i++) {
// printing spaces
for (int j = size; j > i; j--) {
cout << " ";
}
// printing alphabets
for (int k = 0; k < i * 2 - 1; k++) {
if (k == 0 || k == 2 * i - 2) {
cout << ((char)(alpha+num++));
} else {
cout << " ";
}
}
// set the number to 0
num = 0;
cout << "\n";
}
// downside triangle
for (int i = 1; i < size; i++) {
// printing spaces
for (int j = 0; j < i; j++) {
cout << " ";
}
// printing alphabets
for (int k = (size - i) * 2 - 1; k >= 1; k--) {
if (k == 1 || k == (size - i) * 2 - 1) {
cout << ((char)(alpha+num++));
} else {
cout << " ";
}
}
// set the number to 0
num = 0;
cout << "\n";
}
return 0;
}
Output:
A A B A B A B A B A B A B A B A
Conclusion
In this article, we have covered 30 different patterns in C++ using stars, numbers, and alphabets.
If you want to check more pattern programs then look at star pattern in javascript, pattern program in python, and pattern program in java.