
In this article, I will show you the Top 25 Pattern Programs in C++ that you must learn which will help you to understand the usage of nested loops. We will learn to create different geometrical shapes like Squares, triangles, Rhombus, etc. We have provided the code as well as output for all the patterns below.
1. Square Pattern Program in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows " << endl; cin >> n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cout << "*"; } cout << endl; } return 0; }
Output:

2. Hollow Square Pattern Programs in C++
int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i==1 ||i==n||j==1||j==n) { cout << "*"; } else cout << " "; } cout << endl; } return 0; }
Output:

3. Hollow Square Pattern with Diagonal in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i==1 ||i==n||j==1||j==n-i+1||i==j||j==n) { cout << "*"; } else { cout << " "; } } cout << endl; } return 0; }
Output:

4. Right Angled Triangle pattern
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { cout << "* "; } cout << endl; } return 0; }
Output:

5. Hollow Right Angle Triangle pattern
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { if(j==1|| i==j || i==n ) { cout<< "*"; } else cout<< " "; } cout << endl; } return 0; }
Output:

6. Mirrored Right Angle Triangle pattern
#include<iostream> using namespace std; int main() { int i, j, k, rows; cout << "Enter number of rows "; cin >> rows; cout << "Star Pattern\n"; for(i = 1; i <= rows; i++) { for(j = 0; j <= rows - i; j++) { cout << " "; } for(k = 0; k < i; k++) { cout << "*"; } cout << "\n"; } return 0; }
Output:

7. Mirrored Hollow Right Angle Triangle pattern
#include <iostream> using namespace std; int main() { int n; int m = 1; cout << "Enter the number of rows" << endl; cin >> n; cout << "star pattern \n"; for(int i=n; i>=1; i--) { for(int j=1; j<=i-1; j++) { cout << " "; } for(int k=1; k<=m; k++) { if(k==1 || k==m || m==n) cout << "*"; else cout << " "; } cout << endl; m++; } return 0; }
Output:

8. Hollow Inverted Right Angle Triangle
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; m=n; for(int i=1; i<=n; i++) { for(int j=1; j<i; j++) { cout << " "; } for(int k=1; k<=m; k++) { if(i==1 || k==1 || k==m) cout << "*"; else cout << " "; } m--; cout << endl; } return 0; }
Output:

9. Hollow Inverted Mirrored Right Angle Triangle
#include <iostream> using namespace std; int main() { int n; int m = 1; cout << "Enter the number of rows" << endl; cin >> n; for(int i=n; i>=1; i--) { for(int j=1; j<=i; j++) { if(j==1 || j==i || i==n) cout << "*"; else cout << " "; } cout << endl; } return 0; }
Output:

10. Inverted Mirrored Right Angle Triangle
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; m=n; for(int i=1; i<=n; i++) { for(int j=1; j<i; j++) { cout << " "; } for(int k=1; k<=m; k++) { cout << "*"; } m--; cout << endl; } return 0; }
Output:

11. Inverted Right Angle Triangle pattern
#include <iostream> using namespace std; int main() { int n; int m = 1; cout << "Enter the number of rows" << endl; cin >> n; for(int i=n; i>=1; i--) { for(int j=1; j<=i; j++) { cout << "*"; } cout << endl; } return 0; }
Output:

12. Pyramid Pattern Program in C++
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; cout << "Pyramid pattern is\n"; m = n; for(int i=1; i<=n; i++) { for(int j=1; j<=m-1; j++) { cout<< " "; } for(int k=1; k<=2*i-1; k++) { cout << "*"; } m--; cout << endl; } return 0; }
Output:

13. Hollow Pyramid Pattern
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; cout << "Hollow Pyramid pattern is\n"; m = n; for(int i=1; i<=n; i++) { for(int j=1; j<=m-1; j++) { cout << " "; } for(int k=1; k<=2*i-1; k++) { if(k==1 || k==2*i-1 || i==n) cout << "*"; else cout << " "; } m--; cout << endl; } return 0; }
Output:

14. Inverted Pyramid Star Pattern
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; cout << "Inverted Pyramid pattern is\n"; m = 1; for(int i=n; i>=1; i--) { for(int j=1; j<m; j++) { cout << " "; } for(int k=1; k<=2*i-1; k++) { cout << "*"; } m++; cout << endl; } return 0; }
Output:

15. Hollow Inverted Pyramid Pattern
#include <iostream> using namespace std; int main() { int n; int m; cout << "Enter the number of rows" << endl; cin >> n; cout << "Hollow Inverted Pyramid pattern is\n"; m = 1; for(int i=n; i>=1; i--) { for(int j=1; j<m; j++) { cout << " "; } for(int k=1; k<=2*i-1; k++) { if(k==1 || k==2*i-1 || i==n) cout << "*"; else cout << " "; } m++; cout << endl; } return 0; }
Output:

16. Rhombus Pattern in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; cout<< "Rhombus Star Pattern is \n"; for(int i=n; i>=1; i--) { for(int j=1; j<=i-1; j++) { cout << " "; } for(int k=1; k<=n; k++) { cout << "*"; } cout << endl; } return 0; }
Output:

17. Hollow Rhombus Pattern Program in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; cout<< "Hollow Rhombus Star Pattern is \n"; for(int i=n; i>=1; i--) { for(int j=1; j<=i-1; j++) { cout << " "; } for(int k=1; k<=n; k++) { if(i==1 || i==n || k==1 || k==n) cout << "*"; else cout << " "; } cout << endl; } return 0; }
Output:

18. Mirrored Rhombus Pattern in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; cout<< "Mirrored Rhombus Star Pattern \n"; for(int i=1; i<=n; i++) { for(int j=1; j<i; j++) { cout << " "; } for(int k=1; k<=n; k++) { cout << "*"; } cout << endl; } return 0; }
Output:

19. Hollow Mirrored Rhombus Pattern
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; cout<< "Hollow Mirrored Rhombus Star Pattern \n"; for(int i=1; i<=n; i++) { for(int j=1; j<i; j++) { cout << " "; } for(int k=1; k<=n; k++) { if(i==1 || i==n || k==1 || k==n) cout << "*"; else cout << " "; } cout << endl; } return 0; }
Output:

20. Diamond Pattern Program in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows" << endl; cin >> n; cout << "Diamond pattern \n"; int spaces=n-1; int stars=1; for(int i=1; i<=n; i++) { for(int j=1; j<=spaces; j++) { cout << " "; } for(int k=1; k<=stars; k++) { cout << "*"; } if(spaces>i) { spaces=spaces-1; stars=stars+2; } if(spaces<i) { spaces=spaces+1; stars=stars-2; } cout << endl; } return 0; }
Output:

21. Half Diamond Pattern in C++
#include <iostream> using namespace std; int main() { int n, m; cout << "Enter the number of rows" << endl; cin >> n; cout << "Half Diamond pattern \n"; m=1; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { cout << "*"; } cout << endl; } for(int i=n-1; i>=1; i--) { for(int j=1; j<=i; j++) { cout << "*"; } cout << endl; } return 0; }
Output:

22. Plus Pattern in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of rows(only odd)" << endl; cin >> n; cout << "Plus Pattern \n"; for(int i=1; i<=n; i++) { if(i==((n/2)+1)) { for(int j=1; j<=n; j++) { cout << "+"; } } else { for(int j=1; j<=n/2; j++) { cout << " "; } cout << "+"; } cout << endl; } return 0; }
Output:

23. Cross Pattern in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter number of rows"<< endl; cin >> n; int m = 2*n - 1; for ( int i = 1; i <= m; i++ ) { for ( int j = 1; j <= m; j++ ) { if (j == i || j == (m + 1 - i)) cout << "* "; else cout << " "; } cout << endl; } }
Output:

24. Right Arrow Pattern Program in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter number of rows(odd only)"<< endl; cin >> n; for(int i=0; i<n; i++) { for(int j=0; j<i; j++) { cout << " "; } for(int k=1; k<=n-i; k++) { cout << "*"; } cout << endl; } for(int i=1; i<n; i++) { for(int j=1; j<n-i; j++) { cout << " "; } for(int k=1; k<=i+1; k++) { cout << "*"; } cout << endl; } return 0; }
Output:

25. Left Arrow Pattern in C++
#include <iostream> using namespace std; int main() { int n; cout << "Enter number of rows(odd only)"<< endl; cin >> n; cout << "Left Arrow Star Pattern \n"; for(int i=1; i<=n; i++) { for(int j=1; j<=n-i; j++) { cout << " "; } for(int k=0; k<=n-i; k++) { cout << "*"; } cout << endl; } for(int i=1; i<n; i++) { for(int j=1; j<i+1; j++) { cout << " "; } for(int k=1; k<=i+1; k++) { cout << "*"; } cout << endl; } return 0; }
Output:

Conclusion
This brings us to the end of the Top 25 Pattern Programs in C++. I hope this article helped you to get more clarity on the fundamentals of C++. Once you are comfortable with the logic of these patterns, you will be able to write most of the pattern printing programs in C++ on your own.
Thank you for visiting our website.
Also Read:
- Unveiling the Future of AI Detector
- CodeWithHarry Earns 20 Lakhs per month from YouTube?
- Cleaning Service Booking System in Python Tkinter
- Farmers Ecommerce App using Python Tkinter
- Guidelines for Project Collaboration Process
- The system of the binary conversion
- What is web development for beginners?
- Guide to Proxy Servers: How They Work and Why You Need Them?
- Python | Check Armstrong Number using for loop
- Python | Factorial of a number using for loop
- Link in bio
- Microsoft Giving Free Machine Learning Course: Enroll Now
- Accenture Giving Free Developer Certificate in 2023
- Python | Asking the user for input until they give a valid response
- Python | How to iterate through two lists in parallel?
- Amazon Summer Internship 2023
- Python | How to sort a dictionary by value?
- Amazon Giving Free Machine Learning Course with Certificate: Enroll Now
- Google Summer Internship 2023
- Python | How to split a list into equally-sized chunks?
- 5 Secret ChatGPT skills to make money
- Python | Remove items from a list while iterating
- Free Google Certification Courses
- 5 AI tools for coders better than ChatGPT
- Python | How to get dictionary keys as a list
- New secrets to Earn money with Python in 2023
- Flower classification using CNN
- How to represent Enum in Python?
- 5 methods | Flatten a list of lists | Convert nested list into a single list in Python
- What does if __name__ == __main__ do in Python?