This star pattern often makes coding fun and also helps us learn loops smoothly. Stars (*) are mostly used to create cool shapes, improve your logic, as well as problem-solving skills. They often start simple, and you can make them as creative as possible with practice.
Whether you are just starting or already know coding, know how these star pattern programs are a fun way to practice and sharpen your skills. Due to this, learning loops are made more enjoyable and fun.
Program Code
#includeusing namespace std; int main() { int rows; cout << "Rows for pattern: "; // Taking the input from user cin >> rows; for (int i = 1; i <= 5 rows; i++) { loop for rows (int j="1;" <="i;" j++) stars cout << "*"; } endl; move to the next line return 0; output : pattern: * ** *** **** ***** pre> =>
=== Code Execution Successful ===
Explanation :
Program Code
#includeusing namespace std; int main() { int rows; cout << "Rows for pattern: "; // Taking the input from user cin >> rows; for (int i = rows; i >= 1; i--) { // Loop for rows (decreasing) for (int j = 1; j <= 6 i; j++) { loop for stars cout << "*"; } endl; return 0; output : rows pattern: ****** ***** **** *** ** * < pre> =>
=== Code Execution Successful ===
Explanation :
Program Code
#includeusing namespace std; int main() { int rows; cout << "Rows for pattern: "; cin >> rows; for (int i = 1; i <= 5 rows; i++) { for (int j="1;" <="rows" - i; j++) printing spaces cout << " "; * i 1; stars "*"; endl; } return 0; output : rows pattern: *** ***** ******* ********* pre> =>
=== Code Execution Successful ===
Explanation :
Program Code
#includeusing namespace std; int main() { int rows; cout << "Rows for pattern: "; // Taking the input form user cin >> rows; // Upper part of the diamond for (int i = 1; i <= rows; i++) { for (int j="1;" <="rows" - i; j++) cout << " "; * i 1; "*"; endl; } lower part of the diamond>= 1; i--) { for (int j = 1; j <= 5 rows - i; j++) cout << " "; for (int j="1;" <="2" * i 1; "*"; endl; } return 0; output : pattern: *** ***** ******* ********* pre> =>=>
=== Code Execution Successful ===
Explanation :
Program Code
#includeusing namespace std; int main() { int rows; cout << "Rows for pattern: "; cin >> rows; // Upper half of the butterfly for (int i = 1; i <= rows; i++) { for (int j="1;" <="i;" j++) cout << "*"; * (rows - i); spaces in middle " "; right stars endl; } lower half of the butterfly i="rows;">= 1; i--) { for (int j = 1; j <= 6 i; j++) cout << "*"; for (int j="1;" <="2" * (rows - i); " "; endl; } return 0; output.: rows pattern: ** *** **** ***** ************ pre> =>=>
=== Code Execution Successful ===
Explanation :
Below is a comprehensive list of 5 programs that will cover all beginner, intermediate, as well advanced levels. So be ready to grasp. Important learnings from them.
Program Code
# Left-aligned right-angled triangle rows = 6 for i in range(1, rows + 1): for j in range(1, i + 1): print('*', end=' ') print() Output : * * * * * * * * * * * * * * * * * * * * *
Explanation :
Program Code
rows = 5 for i in range(1, rows + 1): for j in range(rows - i): print(' ', end=' ') for k in range(2 * i - 1): print('*', end=' ') print() Output : * * * * * * * * * * * * * * * * * * * * * * * * *
Explanation :
Program Code
rows = 5 for i in range(rows, 0, -1): for j in range(rows - i): print(' ', end=' ') for k in range(2 * i - 1): print('*', end=' ') print() Output : * * * * * * * * * * * * * * * * * * * * * * * * *
Explanation :
Program Code
rows = 5 # Upper half for i in range(1, rows + 1): for j in range(rows - i): print(" ", end="") for k in range(2 * i - 1): if k == 0 or k == 2 * i - 2: print("*", end="") Else: print(" ", end="") print() # Lower half for i in range(rows - 1, 0, -1): for j in range(rows - i): print(" ", end="") for k in range(2 * i - 1): if k == 0 or k == 2 * i - 2: print("*", end="") Else: print(" ", end="") print() Output : * * * * * * * * * * * * * * * *
Explanation :
Program Code
# Butterfly pattern n = 5 # Upper half for i in range(1, n + 1): print('*' * i + ' ' * (2 * (n - i)) + '*' * i) # Lower half for i in range(n, 0, -1): print('*' * i + ' ' * (2 * (n - i)) + '*' * i) Output : * * ** ** *** *** **** **** ********** **** **** *** *** ** ** * *
Explanation :
As we have seen here, C++ as well as Python have their own set of merits and demerits. So one should choose them according to their needs, requirements, and skillset. Budget should also be taken into account while you choose a particular program. But learning this never goes to waste, so just enroll for a C programming course in Noida and also a Python programming course in Noida at one of the institutions, and let your career leap to the next level. Make a wise choice and build your career in the right direction. Feel free to contact us or visit our website for more courses or details. All trending courses are available as per industry demands to suit your needs and help you land your dream job. You can also enroll in other courses of your choice and perform well. The right career is important, along with your interest, so look for both. Choose a job of your dreams and make your step count in this tech-savvy world. Be wise and choose what you need as per industry demands.
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding