20 Easy Patterns and Shapes in C++: Star, Pyramid, Triangles

Here I’ve shared various star, triangle, pyramids patterns and shapes 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 different 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 patterns and shapes you want me to upload for everyone’s help.

Patterns and shapes

Following are the various Patterns and shapes in C++:

1. C++ Program To display the half pyramid of *, numbers and character.

*
* *
* * *
* * * *
* * * * *

 

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

 

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

 

4. C++ Program to print inverted half pyramid using * as shown below:

* * * * *
* * * *
* * *
* *
*

 

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

 

6. C++ Program To display the pyramid of * and digits.

        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *

 

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

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

9. C++ program to display reverse pyramid.

* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *

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

11. C++ Program to display Floyd’s Triangle.

1
2 3
4 5 6
7 8 9 10

12. C++ Program to draw inverted hollow triangle.

* * * * * * *
 *         *
   *     *
     * *
      *

13.  C++ Program to display following pattern:

A
B C
D E F
G H I J
K L M N O

Above were some common patterns and shapes and now we will discuss another list of patterns and shapes which are asked in various Interviews.

14. C++ program to print inverted right triangle using * as below:

* * * * *
  * * * * 
    * * *
      * *
        *

15. C++ program to print square pattern using * as below:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

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

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

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

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

 

20. C++ program to below pattern:

*
*
*
* * * * * * *
*
*
*

Keep asking for new patterns and shapes in C++, I’ll keep adding them to the list, also comment in case you find any issue with patterns and shapes.

108 thoughts on “20 Easy Patterns and Shapes in C++: Star, Pyramid, Triangles”

    • #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;//
      }

      Reply
  1. 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++?

    Reply
    • 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;
      }
      ___________

      Reply
  2. * * * * * * * * * * * * * * * * * * * * *
    * * * * * * * * *
    * * * * * * * *
    * * * * * * *
    * * * * * *
    * *
    * * * * * * * * * * * * * * * * * * * * *

    Plz send me code….

    Reply
    • #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;
      }
      }

      Reply
    • #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;
      }

      Reply
    • 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;}

      Reply
    • 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;
      }

      Reply
    • #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;
      }

      }

      Reply
  3. 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();
    }

    Reply
  4. Sir, I’d made a pattern in c++ in very complicated format. Can you please make it short and easy.
    *
    * *
    * * *
    * * * *
    * * * * *
    * *
    * * * *
    * * * * * *
    * * * *
    * *
    * * * * *
    * * * *
    * * *
    * *
    *

    Reply
    • 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;
      }

      Reply
    • #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");
      }

      Reply
    • #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; }

      Reply

Leave a Comment