Star Pattern in C++ (15 Programs With Output)
Star Pattern in C++ (15 Programs With Output)
Home Resources C++ Tutorial | Learn CPP Programming Language Program Star Pattern In C++ (1...
Share
English
Coders ki Tipaniya:
Spaces aur stars ka ho sahi
distribution, tabhi hoga perfect
pattern execution!
#include <iostream>
using namespace std;
https://www.wscubetech.com/resources/cpp/programs/star-pattern 1/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
int main() {
int rows;
cout << "Rows for pattern: "; // Taking the input from use
cin >> rows;
Output:
Code explanation:
We take a number from the user to decide how many rows the pattern
will have.
We use a loop to go through each row and another loop inside it to
print stars (*).
The number of stars in each row increases as we move to the next
row. After printing stars for a row, we move to the next line to create
the pattern.
#include <iostream>
using namespace std;
https://www.wscubetech.com/resources/cpp/programs/star-pattern 2/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
int main() {
int rows;
cout << "Rows for pattern: "; // Taking the input from use
cin >> rows;
Output:
Code explanation:
First, we take a number from the user to decide how many rows the
pattern is.
We use the first loop to go through each row and another loop inside it
to print stars (*), decreasing the number of stars in each row.
After printing stars for a row, we move to the next line, creating an
inverted star pattern in C++.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
https://www.wscubetech.com/resources/cpp/programs/star-pattern 3/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
Output:
Code Explanation:
We take a number from the user to decide how many rows the pattern
will have.
A loop creates each row, adding spaces first to align the stars (*) in a
pyramid shape.
The number of stars increases in each row, forming a star pattern in
C++ that looks like a pyramid.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
Output:
Code explanation:
We first take the number of rows as input from the user to decide the
size of the pattern.
A loop creates each row, adding spaces first to align the stars (*) in an
inverted pyramid shape.
The number of stars decreases in each row, forming an inverted star
pattern in a C++ program that looks like an upside-down pyramid.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: "; // Taking the input form use
cin >> rows;
return 0;
}
Output:
Code explanation:
We first take the number of rows as input from the user to decide the
size of the pattern.
We use loops to print spaces and stars (*), first creating the upper
part of the diamond and then the lower part.
The stars increase in the upper part and decrease in the lower part,
forming a diamond-shaped star pattern in the output.
https://www.wscubetech.com/resources/cpp/programs/star-pattern 6/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: "; // Taking the input from use
cin >> rows;
Output:
Code Explanation:
We first take the number of rows as input from the user for the
pattern.
We use loops to print stars (*) on the border while keeping the inside
empty by printing spaces.
This creates a star pattern in C++ that looks like a hollow square, with
stars on the edges and spaces inside.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
Output:
Code explanation:
We first take the number of rows as input from the user to decide the
size of the pattern.
We use loops to print stars (*) on the boundary while keeping the
inside empty by printing spaces.
This creates a star pattern in C++ that looks like a hollow right-angled
triangle, with stars on the edges and spaces inside.
https://www.wscubetech.com/resources/cpp/programs/star-pattern 8/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
#include <iostream>
using namespace std;
int main() {
int rows = 5;
return 0;
}
Output:
*
**
***
****
*****
****
***
**
*
Code explanation:
We first set the number of rows to 5, which decides the size of the
pattern.
We use loops to print an increasing number of stars (*) in the first half
and then a decreasing number of stars in the second half.
#include <iostream>
using namespace std;
int main() {
int rows = 5;
return 0;
}
Output:
*
**
***
****
*****
****
***
**
*
Code explanation:
We first set the number of rows to 5, which decides the size of the
pattern.
https://www.wscubetech.com/resources/cpp/programs/star-pattern 10/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
Output:
https://www.wscubetech.com/resources/cpp/programs/star-pattern 11/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
Code explanation:
We first take the number of rows as input from the user to decide the
size of the pattern.
We use loops to print spaces first, followed by stars (*) on the
boundary while keeping the inside empty.
This creates a hollow pyramid shape, where the stars form the outline,
and the inside remains empty.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
return 0;
}
https://www.wscubetech.com/resources/cpp/programs/star-pattern 12/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
Output:
Code explanation:
We first take the number of rows as input from the user to determine
the size of the pattern.
The pattern has two halves, upper and lower, forming mirror images.
We use loops to print stars (*) on both sides and spaces in the middle
to create the butterfly shape.
This results in a star pattern in C++, where stars expand outward and
then shrink symmetrically.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
https://www.wscubetech.com/resources/cpp/programs/star-pattern 13/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
return 0;
}
Output:
https://www.wscubetech.com/resources/cpp/programs/star-pattern 14/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
Code explanation:
We first take the number of rows as input from the user to decide the
pattern size.
The pattern is divided into two upper and lower halves, forming a
symmetrical butterfly shape.
We use loops to print stars (*) on the edges while keeping spaces
inside, giving it a hollow effect.
This creates a star pattern program in C++, making a unique butterfly
outline with hollow spaces in the middle.
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Rows for pattern: ";
cin >> size;
return 0;
}
Output:
https://www.wscubetech.com/resources/cpp/programs/star-pattern 15/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
Code explanation:
We first take the number of rows as input and ensure it is an odd
number for symmetry.
We use loops to print stars (*) in the middle row and middle column
while keeping spaces elsewhere.
This creates a plus-shaped pattern, where the stars form a cross in
the center of the given size.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows;
return 0;
}
Output:
Code Explanation:
We first take the number of rows as input from the user to decide the
pattern size.
We use loops to print spaces first, then stars (*) on the boundary
while keeping the inside empty.
The star pattern program in C++ prints a hollow diamond, with stars
forming the outer shape and spaces inside.
The first half prints the upper part, and the second half completes the
lower part of the diamond.
https://www.wscubetech.com/resources/cpp/programs/star-pattern 17/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Rows for pattern: ";
cin >> rows ;
Output:
Code Explanation:
We first take the number of rows as input from the user to decide the
pattern size.
We use loops to print stars (*) on both diagonals while keeping
spaces elsewhere.
This forms an "X" shape, where stars appear at the positions where
the row and column numbers match or add up to the given rows.
https://www.wscubetech.com/resources/cpp/programs/star-pattern 18/20
6/22/25, 12:02 PM Star Pattern in C++ (15 Programs With Output)
https://www.wscubetech.com/resources/cpp/programs/star-pattern 20/20