Here I’ve shared various star, triangle, pyramids patterns and shapes program in C++ using asterisks, numbers, alphabets etc. These are simple program which require basic programming knowledge.
Examples to print half pyramid, pyramid, inverted pyramid, Pascal’s Triangle and Floyd’s triangle in C++ Programming using control statements.
Printing these patterns is not easy if you don’t have basic idea of using loops, once you get a basic idea of these pattern programs shared below, you can make any pattern or shape instantly. Hope you find these useful and keep commenting for the new shapes or patterns you want me to upload for everyone’s help.

Following are the various Patterns and shapes in C++ Programming:
1. C++ Program To display the half pyramid of *, numbers and character.
*
* *
* * *
* * * *
* * * * *
#include <iostream>
using namespace std;
int main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}
2. C++ Program to print half pyramid as using numbers as shown in figure below.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include <iostream>
using namespace std;
int main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
cout<<j<<" ";
}
cout<<"\n";
}
return 0;
}
3. C++ Program to print triangle of characters as below:
A
B B
C C C
D D D D
E E E E E
#include <iostream>
using namespace std;
int main()
{
int i,j;
char input,temp='A';
cout<<"Enter uppercase character you want in triangle at last row: ";
cin>>input;
for(i=1;i<=(input-'A'+1);++i)
{
for(j=1;j<=i;++j)
cout<<temp<<" ";
++temp;
cout<<endl;
}
return 0;
}
4. C++ Program to print inverted half pyramid using * as shown below:
* * * * *
* * * *
* * *
* *
*
#include <iostream>
using namespace std;
int main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=rows;i>=1;--i)
{
for(j=1;j<=i;++j)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}
5. C++ Program to print inverted half pyramid as using numbers as shown below.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
#include <iostream>
using namespace std;
int main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=rows;i>=1;--i)
{
for(j=1;j<=i;++j)
{
cout<<j<<" ";
}
cout<<"\n";
}
return 0;
}
6. C++ Program To display the pyramid of * and digits.
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
#include <iostream>
using namespace std;
int main()
{
int i,space,rows,k=0;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
cout<<" ";
}
while(k!=2*i-1)
{
cout<<"* ";
++k;
}
k=0;
cout<<"\n";
}
return 0;
}
7. C++ program to print the pyramid of digits in pattern as below.
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
#include <iostream>
using namespace std;
int main()
{
int i,space,rows,k=0,count=0,count1=0;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
cout<<" ";
++count;
}
while(k!=2*i-1)
{
if (count<=rows-1)
{
cout<<i+k<<" ";
++count;
}
else
{
++count1;
cout<<i+k-2*count1<<" ";
}
++k;
}
count1=count=k=0;
cout<<"\n";
}
return 0;
}
8. C++ program to draw isosceles triangle using alphabets EDCBA
A
C B A
E D C B A
G F E D C B A
I H G F E D C B A
#include<iostream>
using namespace std;
int main()
{
int value;
cout << "Enter the size = ";
cin >> value;
int space = value;
for (int i = 0; i < value; i++) {
for (int j = space; j > 0; j--) {
cout << " ";
}
for (int star = i * 2; star >= 0; star--) {
cout << char(star + 65);
}
space--;
cout << endl;
}
return 0;
}
9. C++ program to display reverse pyramid.
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
#include <iostream>
using namespace std;
int main()
{
int rows,i,j,space;
cout<<"Enter number of rows: ";
cin>>rows;
for(i=rows;i>=1;--i)
{
for(space=0;space<rows-i;++space)
cout<<" ";
for(j=i;j<=2*i-1;++j)
cout<<"* ";
for(j=0;j<i-1;++j)
cout<<"* ";
cout<<endl;
}
return 0;
}
10. C++ Program to Draw Pascal’s triangle as below.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
#include <iostream>
using namespace std;
int main()
{
int rows,coef=1,space,i,j;
cout<<"Enter number of rows: ";
cin>>rows;
for(i=0;i<rows;i++)
{
for(space=1;space<=rows-i;space++)
cout<<" ";
for(j=0;j<=i;j++)
{
if (j==0||i==0)
coef=1;
else
coef=coef*(i-j+1)/j;
cout<<" "<<coef;
}
cout<<endl;
}
}
11. C++ Program to display Floyd’s Triangle.
1
2 3
4 5 6
7 8 9 10
#include <iostream>
using namespace std;
int main()
{
int rows,i,j,k=0;
cout<<"Enter number of rows: ";
cin>>rows;
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;++j)
cout<<k+j<<" ";
++k;
cout<<endl;
}
return 0;
}
12. C++ Program to draw inverted hollow triangle.
* * * * * * *
* *
* *
* *
*
#include<iostream>
using namespace std;
int main()
{
cout<<""Inverted Triangle Shape"\n\n";
int w=6;
for(int g=0;g<9;g++)
{
cout<<"*"; // Displaying asterisk here
}
cout<<endl; // endl is for new line
for(int a=1;a<=3;a++)
{
for(int b=0;b<a;b++)
{
cout<<" "; // displaying space here
}
cout<<"*";
for(int c=1;c<w;c++)
{
cout<<" ";
}
cout<<"*"<<endl;
w=w-2;
}
for(int e=1;e<=1;e++)
{
for(int f=4;f>=e;f--)
{
cout<<" ";
}
cout<<"*";
}
return 0;
}
13. C++ Program to display following pattern:
A
B C
D E F
G H I J
K L M N O
#include <iostream>
using namespace std;
int main()
{
int i,j,n;
char c;
cout<<"Enter number of rows:";
cin>>n;
c='A';
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(c=='Z')
break;
cout<<c;
c++;
}
cout<<endl;
}
return 0;
}
14. C++ program to print inverted right triangle using * as below:
* * * * *
* * * *
* * *
* *
*
#include<iostream>
using namespace std;
void main() {
int value = 0;
cout << "Enter Value for the size of Triangle = ";
cin >> value;
int temp = value;
for (int i = 0; i < value; i++) {
for (int space = 0; space < i; space++)
{
cout << " ";
}
for (int star = 0; star < temp; star++)
{
cout << "*";
}
temp--;
cout << endl;
}
}
15. C++ program to print square pattern using * as below:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
#include<iostream>
using namespace std;
int main()
{
int square;
cout<<"Enter The Size of Square = ";
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int i = 1;i<=square;i++) //inner loop
{
cout<<"*";
}
cout<<endl;//new line for next line output
}
return 0;
}
16. C++ program to print square pattern using numbers as below:
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
#include<iostream>
using namespace std;
int main()
{
int square;
cout<<"Enter The Size of Square = ";
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j = 1;j<=square;j++) //inner loop
{
cout<<i<<" ";
}
cout<<endl;//new line for next line output
}
return 0;
}
17. C++ program to print square pattern as below:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
#include<iostream>
using namespace std;
int main()
{
int square;
cout<<"Enter The Size of Square = ";
cin>>square;
for(int i=1; i<=square; i++) // outer loop
{
for(int j=1; j<=square; j++) //inner loop
{
cout<<j<<" "; // value that is output
}
cout<<endl;
}
return 0;
}
18. C++ program to print square pattern as below:
A A A A A
B B B B B
C C C C C
D D D D D
E E E E E
#include<iostream>
using namespace std;
int main()
{
int square;
cout<<"Enter The Size of Square = ";
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j = 1;j<=square;j++) //inner loop
{
cout<<char(i+64)<<" "; // value that is output
}
cout<<endl;
}
return 0;
}
19. C++ program to print square pattern as below:
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
#include<iostream>
using namespace std;
int main()
{
int square;
cout<<"Enter The Size of Square = ";
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j = square;j>=1;j--) //inner loop
{
cout<<j<<" "; // value that is output
}
cout<<endl;
}
return 0;
}
20. C++ program to below pattern:
*
*
*
* * * * * * *
*
*
*
#include
using namespace std;
int main()
{
int i,j,rows;
rows=7;
for(i=1;i<=rows;++i)
{
for(j=1;j<=7;++j)
{
if (i==4)
cout<<"* ";
}
cout<<"* ";
cout<<"\n";
}
return 0;
}
Keep asking for new patterns and shapes in C++, I’ll keep adding them to the list.
Very simple and easy
can u send me ur email id plz
give me tutions
****
****
****
****
what is the code of the this pattern?
*
**
***
*****
please help me.
for ( int i=1; i<5; i++)
{
for ( int j=1; j<i; j++)
{
cout<<"*";
}
}
how about
2
642
8642
108642
?
int input;
cin>>input;
int n=2;
int decremnt = 2;
for(int i=1; i<=input; i++)
{
int temp = n+2;
for(int j=0; j0)
{
cout<<temp-decremnt;
temp -= 2;
}
}
cout<<endl;
n+=2;
}
oh, not that . the 2’s are all align.
all example is very simple & easy but some example explain is complicated way
congrats for your support in programming,,,,,,,can i get a code to draw the shape of a star using asteriks
can you please explain what type of star?
Admin plz make this.. *****
** *
* * *
*****
Sorry cannot understand your pattern. Please write from next line.
Please help
Insert uppercase character:E
E D C B A B C D E
D C B A B C D
C B A B C
B A B
A
A is vertical align. Pattern should be like inverted pyramid
Use 8th program above. Just take a variable as
ascii value of ‘A’ and increment or decrement it accordingly
#include
#include
void main()
{
int i,j,n;
char c;
clrscr();
cout<>n;
c=’A’;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(c=='Z')
break;
cout<<c;
c++;
}
cout<<endl;
}
return 0;
}
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1
Using Five LOOPs ………………..
plz can anyone tell me about this program that how we display the following pattern using nested for loop in c++:
1 2 3 4 5
1 3 5 7 11
1 4 7 10 13
?
pls help me to draw this pattern
*
* *
* * *
* * * *
* * * * * * * * * *
* * * *
* * *
* *
*
#include
using namespace std;
int main()
{
for(int i=0;ii;j–)
cout<< " ";
{ for(int k=0;k<=i;k++)
cout<<"* ";}
cout<=1;l–)
{ for (int m=0;m<=3-l;m++)
cout<<" ";
{ for (int n=0;n<=l;n++)
cout<<"* ";
}
cout<<endl;
}
//cout<<endl;//
}
1 2 3 4 5 6 7 8 9 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19
can anyone one help me with this pattern using c++?
this is cyclic pattern..available in net..
#include
using namespace std;
int main()
{
int n;
cout<>n; /*n Size of the array*/
int A[n][n];
int len=n,k=1,p=0,i; /*k is to assign the values to the array from 1…n*n */
/*len is used to update(decrease) array size so that values cans be assign to them */
while(k<=n*n)
{
for(i=p;i<len;i++) /*Loop to access the first row of the array*/
{
A[p][i]=k++;
}
for(i=p+1;i=p;i–) /*Loop to access the last row of the array*/
{
A[len-1][i]=k++;
}
for(i=len-2;i>p;i–) /*Loop to access the first column of the array*/
{
A[i][p]=k++;
}
p++,len=len-1;
}
if(!n%2) /*This block will run only if n is even*/
{
A[(n+1)/2][(n+1)/2]=n*n; /*It will assign the last value to the centremost element*/
}
for(i=0;i<n;i++) /*This loop will print the array in matrix format*/
{
for(int j=0;j<n;j++)
{
cout<<A[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}
___________
anyone can tell how to make +,-%,/ theses shapes by using asteroid
sorry its asteric * not asteroid
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* *
* * * * * * * * * * * * * * * * * * * * *
Plz send me code….
Draw a Square and write in side MIT
I want a coding for * *
* *
* *
* *
* *
* *
In cpp
Plz reply…
int main(){
for(int i=1;i<=5;i++){
for(int j=1;j<=2;j++){
cout<<"*"; }
cout<<endl; }
return 0;}
Can u plz tell me
1
10
101
1011
10111
#include
using namespace std;
int main()
{
int h;
cout<<"Enter Hieght : "<>h;
for(int i = 0;i<h;i++)
{
for(int j=0;j<=i;j++)
{
if(j == 1)
{
cout<<"0";
}
else
cout<<"1";
}
cout<<endl;
}
}
can you please explain how to draw an E of “*” using odd numbers above 5?
thank yo u
03051492800
plz help me to make this pattern
* *
* * * *
* * * * * *
* * * * * *
#include
using namespace std;
int main()
{
int i,j;
for(i=1; i<=3; i++)
{
for(j=1; j<=i; j++)
{
cout<<"**";
}
cout<<endl;
}
cout<<"******"<<endl;
system("pause");
return 0;
}
int main(){
for(int i=1;i<=8;i++){
if(i%2==0){
for(int j=1;j<=i;j++){
if(i==8){
i=6;}
cout<<"*";}
cout" \n";}
return 0;}
hi can anyone help me with this by using for loops
***1
**21
*321
4321
int main(){
for(int i=1;i=i;s–){
cout<=1;j–){
cout<<j;}
cout<<endl;}
return 0;}
please help with
1
21
321
4321
54321
int j=0;
for(int i=1;ij;k–)
{
cout<<k<<" ";
}
cout<<endl;
}
#include
using namespace std;
int main()
{
int i,j.c;
for(i=1;i<=5;i++)
{
c=i;
for(j=1;j<=i;j++)
{
cout<<c;
c– ;
}
cout<<endl;
}
}
int main()
{
int height=0; //Code is generic
cout<>height;
int a=height;
for(int i=1;i<=height;i++)
{
for(int j=1;j<a;j++)
{
cout<=1;k–)
{
cout<<k;
}
cout<<endl;
}
return 0;
}
if n=4,output is
1 2 3 4
9 10 11 12
13 14 15 16
5 6 7 8
pls suggest me logic
hi can anyone help me with this by using for loops
55555
44444
33333
22222
11111
#include
using namespace std;
int main()
{
int h=5,a=h;
for(int h=5;h>0;h–)
{
for(int i=0;i<a;i++)
{
cout<<h;
}
cout<<endl;
}
}
Hello Dear how to create bellow pyramid
1
121
12321
1234321
123454321
please create this pattern for me..
12345
23451
34512
45123
51234
12345
1 1
12 3
123 6
1234 10
12345 15
plzz help me admin
int main()
{
int height=0;
cout<>height;
int a=1;
for(int i=1;i<=height;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
cout<<" ";
for(int k=1;k<=1;k++)
{
cout<<a;
}
a=a+i+1;
cout<<endl;
}
return 0;
}
1
212
32123
what about this
123
894
765
please friend solve this pattern and code return me
how to write this program plz help
****5
***4 8
**3 6 9
*2 4 8 12
1 2 3 4 5
How can i print
#*****
*#****
**#***
***#**
****#*
*****#
#include
using namespace std;
int main(){
int i,j,k;
for(i=1;i<=6;i++)
{
for(j=1;j<=6;j++){
if( i==j)
cout<<"#";
else
cout<<"*";
}cout<<endl;
}
}
pls. show me how to make this
1 1
12 21
123 321
1234321
#include
using namespace std;
int main()
{
for(int i=0; i<6; i++)
{
for(int j=0;j<6; j++)
{
if(i==j)
{
cout<<"#";
}
else
{
cout<<"*";
}
}
cout<<endl;
}
return 0;
}
itni tuf lgti aaa mjy programming m kia krn
Keep Calm and Code ON …..
Hey admin… Help me solve this
5555555555
4444 4444
333 333
22 22
1 1
Oops.. It’s like this
5555555555
4444 4444
333 333
22 22
1 1
All the students plz Keep Calm and Code ON ….
1
11
101
1001
#
#
# # # # #
#
#
need help to print this
*****
* *
* *
* *
*****
Please help to give the proper coding for this question
*
* *
* * *
* * * *
* * * * *
#include
using namespace std;
int main()
{
int i,j;
for(i=1;i<=6;i++){
for(j=1;j<=i;j++){
cout<<"*";
}cout<<endl;
}
}
I want a flight symbol…
Pls help me
plz help me for this pattern
**********
**** ****
*** ***
** **
* *
*****
***
*
***
*****
plzzz code 4this
BAASARA NIZAM this is code for your triangle pattern
#include
#include
void main()
{
int i,j;
clrscr();
for(i=1; i<=5; i++)
{
for(j=1; j<i; j++)
{
cout<<"*";
}
cout<<"\n";
}
getch();
}
Sir, I’d made a pattern in c++ in very complicated format. Can you please make it short and easy.
*
* *
* * *
* * * *
* * * * *
* *
* * * *
* * * * * *
* * * *
* *
* * * * *
* * * *
* * *
* *
*
*****
* *
* *
*****
pls help me to draw this.
it is not typed here correctly actually its like a vertical rectangle ….
how to draw that pattern?
1
2 2
3 3
4 4
please help me insert upper case character
A
AB
ABC
ABCD
ABCDE
int main()
{
char ch=’A’;
int height=0;
cout<>height;
for(int i=0;i<height;i++)
{
for(int j=0;j<=i;j++)
{
cout<<ch;
ch++;
}
ch='A';
cout<<endl;
}
return 0;
}
please! display the following out put using their ASCII values
a
bc
def
gehi
jklmn
opqrst
int main()
{
char ch=’a’;
int height=0;
cout<>height;
for(int i=0;i<height;i++)
{
for(int j=0;j<=i;j++)
{
cout<<ch;
ch++;
}
cout<<endl;
}
return 0;
}
can you do this for me
0
1 0 1
2 1 0 2 1
3 2 1 0 3 2 1
4 3 2 1 0 1 2 3 4
0 must be aligned in same line
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1
int main()
{
int height=0; //Code is generic.Height should be even number.
cout<>height;
for(int i=1;i<=height/2;i++)
{
for(int j=1;j<=i;j++)
{
cout<<i<<"*";
}
cout<=1;i–)
{
for(int j=i;j>=1;j–)
{
cout<<i<<"*";
}
cout<<endl;
}
return 0;
}
1_______1
12_____21
123___321
1234_4321
123___321
12_____21
1_______1
can u help me with this pattern
**
**
****
****
******
******
Can u help me ?👆👆
12345
234567
345678
9
45678910
* *
* *
* *
* *
* * * * *
6
54
321
Plz help me what will be the code of this output
What about
0
0 2
0 2 4
0 2 4 6
0 2 4 6 8
0 2 4 6
0 2 4
0 2
0
#include
#include
#include
using namespace std;
int main()
{
int ahmed,khaled;
cout << "enter the number" <> ahmed>>khaled;
for (int i = 0; i <=ahmed; i+=2)
{
for (int j = 0; j <= i; j+=2)
{
cout << j;
}
cout <= 0; h -= 2)
{
for (int y = 0; y <= h; y += 2)
{
cout << y;
}
cout << endl;
}
system("pause");
}
1
23
345
5678
how to print this pattern
int main()
{
int height=0,a=1;
cout<>height;
for(int i=1;i<=height;i++)
{
for(int j=1;j<=i;j++)
{
cout<=2)
{
a=a-1;
}
cout<<endl;
}
return 0;
}
how about
1 2 3
8 9 4
7 6 5
or
1 2 3 4 5
16 17 18 19 6
15 23 24 25 7
14 22 21 20 8
13 12 11 10 9
in c++
How to make this pattern:
A
A B
A B C
A B C D
A B C D E
Plz Help me with this pattern…
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
please help me with this pattern
* *
** **
*** ***
*******
*** ***
** **
* *
how to make in c++
enter number :
cin >> 5
5 4 3 2 1
4 5 4 3 2
3 4 5 4 3
2 3 4 5 4
1 2 3 4 5
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
can you print this pattern!! urgent !!!!
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
print this !!!
…………1
………2 1 2
……3 2 1 2 3
…4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
1010
1010
1010
I want to make a pattern like this using only while or do while loop
*
**
***
****
*****
******
*******
what could be the code fro the following pattern :
*****
%****
%%**
%%%**
%%%%*
Help me draw uk flag
help me with this shape pls only one space beetwen
*
*
*
* * * * * * *
*
*
*
#include
using namespace std;
int main()
{
int i,j,rows;
rows=7;
for(i=1;i<=rows;++i) { for(j=1;j<=7;++j) { if (i==4) cout<<"* "; } cout<<"* "; cout<<"\n"; } return 0; }