Patterns Programs List in C++

PATTERN PROGRAMS IN C++

Here in this Page you found all Complex Patterns Programs List in C++

Before starting to Create Patterns Programs in C++ Make sure you read Create Patterns in C++

Complex Patterns Programs List in C++


 

1. Create a Solid Square in C++

#include<iostream.h> 
#include<conio.h>
  
void main()
 {
    int i,j,n;
    cout<<"Enter Number: ";
    cin>>n;
for(i=1; i<=n; i++) { int j=1; while(j<=n*2) { cout<<"*"; j++; } cout<<endl; } getch(); }
OUTPUT:-
Enter Number of rows: 5

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

2. Create a Pyramid in C++

#include<iostream.h> 
#include<conio.h>

 void main()
 {
   int row;
   clrscr();
   cout<<"Enter number of rows: ";
   cin>>row;

    for(int i=1; i<=row; i++)
     {
	int j=1;
	while(j<=row-i)
	 {
	   cout<<" ";
	   j++;
	 }
	for(int k=0; k<=(i*2)-2; k++)
	    cout<<"*";
        cout<<endl;
     }

   getch();
 }
OUTPUT:-
Enter number of rows: 5

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

Here is another one,

#include<iostream.h>
#include<conio.h>

 void main()
  {
    int row,count=1;
    clrscr();
    cout<<"Enter Number of rows: ";
    cin>>row;

     for(int i=1; i<=row; i++)
      {
	for(int j=1;j<=row-i;j++)
	    cout<<" ";

	for(int k=i; k>=1; k--)
	 {
	    if(k==1)
	       cout<<count++;
	    else
	       cout<<"*";
	 }

	for(int l=2; l<=i; l++)
	   cout<<"*";

	cout<<endl;
     }
  getch();
 }
OUTPUT:-

Enter Number of rows: 5
    1       
   *2* 
  **3**  
 ***4*** 
****5****  

3. Creating a Reverse Pyramid in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,n;clrscr();
    cout<<"Enter number of row: "; cin>>n;

    cout<<endl;

     for(i=1; i<=n; i++)
      {
	for(j=0; j<i; j++)
	   cout<<" ";
	for(int k=0; k<=n*2-i*2; k++)
	   cout<<"*";
	cout<<endl;
      }

   getch();
 }
OUTPUT:-
Enter number of row: 5
 *********
  *******
   *****
    ***
     *

Here is another one,

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter Number of rows: "; cin>>row;

   cout<<endl;

    i=1;
    while(i<=row)
     {
       for(j=1;j<=i;j++)
	   cout<<" ";

       for(k=1; k<=row-i; k++)
	   cout<<"*"<<" ";

       cout<<endl;
     i++;
    }
   getch();
 }
OUTPUT:-
Enter Number of rows: 6

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

4 .Create a  Straight Pyramid and Reverse Pyramid 

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   cout<<endl;
//upper part
    for(i=1;i<=row;i++)
     {
       for(j=1;j<=row-i;j++)
	   cout<<" ";

       for(k=1; k<=i*2-1; k++)
	   cout<<"*";

       cout<<endl;
     }

//lower part
   for(i=1;i<=row;i++)
     {
       for(j=1;j<=i;j++)
	   cout<<" ";

       for(k=1; k<=(row-i)*2-1; k++)
	   cout<<"*";

       cout<<endl;
     }

   getch();
 }
OUTPUT:-
Enter Number of rows: 5
          
    *  
   *** 
  *****  
 ******* 
********* 
 *******
  *****    
   ***   
    *

5. Create Triangle with other Reverse Triangle

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   cout<<endl;

//upper part
     for(i=1;i<=row;i++)
       {
	 for(j=1;j<=row-i;j++)
	   cout<<" ";

	 for(k=1; k<=i*2-1; k++)
	  {
	    if(k==1 || k==i*2-1)
	       cout<<"*";
	    else
	      cout<<" ";
	  }

	cout<<endl;
      }

//lower part
   for(i=1;i<=row;i++)
     {
       for(j=1;j<=i;j++)
	   cout<<" ";

       for(k=1; k<=(row-i)*2-1; k++)
	 {
	    if(k==1 || k==(row-i)*2-1)
	      cout<<"*";
	    else
	      cout<<" ";
	 }

       cout<<endl;
     }

   getch();
 }
OUTPUT:-
Enter the number: 5
              
    *  
   * *  
  *   * 
 *     * 
*       * 
 *     *
  *   *
   * *
    *

6. Create a Isoscles Triangle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,k,row;
    clrscr();
    cout<<"Enter Number of rows: "; cin>>row;

     for(i=1;i<=row;i++)
      {
        for(j=1;j<=row-i;j++)
	   cout<<" ";
        for(k=1;k<=2*i-1;k++)
	 {
	   if(i<row)
	     {
	       if((k==1)||(k==2*i-1))
	           cout<<"*";
	       else
		  cout<<" ";
	     }
	   if(i==row)
	      cout<<"*";
         }
        cout<<endl;
      }

   getch();
 }
OUTPUT:-
Enter Number of rows: 5

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

7. Create a Equilateral Triangle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
 {
   int row;
   clrscr();
   cout<<"Enter number of rows: "; cin>>row;

   cout<<endl;

    for(int i=1; i<=row; i++)
     {
	int j=1;
	while(j<=row-i)
	 {
	   cout<<"  ";
	   j++;
	 }
	for(int k=0; k<=(i*2)-2; k++)
	  {
	   if(k==0 || i==row || k==(i*2)-2)
	      cout<<" *";
	   else
	      cout<<"  ";
	  }
       cout<<endl;
     }
   getch();
 }
OUTPUT:-
Enter number of rows: 5

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

Here is another one,

#include<iostream.h> 
#include<conio.h>

 void main()
 {
   int row;
   clrscr();
   cout<<"Enter number of rows: "; cin>>row;

   cout<<endl;

    int i=1;
    while(i<=row)
     {
	for(int j=1; j<=row*2-i*2;j++)
	    cout<<" ";

	for(int k=1; k<=((2*i)-1)*2; k++)
	  {
	    if(i==1)
	     {
	          if(k==1)  
                     cout<<"/\\";
	     }						     
	    else if(k==1)
		  cout<<"/";
	    else if(k==((2*i)-1)*2)
		  cout<<"\\";
	    else if(i==row)
		  cout<<"_";
	    else
		  cout<<" ";
	  }
       cout<<endl;
       i++;
     }
   getch();
 }
OUTPUT:-
Enter number of rows: 5

        /\
       /  \
      /    \
     /      \
    /________\

8. Create a Right-Angle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   i=1;
   while(i<=row)
    {
      for(j=1;j<=i;j++)
       {
	 if(i==1 || j==1 || i==j || i==row)
	   cout<<"*";
	 else
	   cout<<" ";
       }
      cout<<endl;
      i++;
    }

   getch();
 }
OUTPUT:-
Enter the number: 5
*
**
* *
*  *
*****

9. Create a Obtuse Triangle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int row,i,j,s;
    clrscr();
    cout<<"Enter size: "; cin>>row;

    if(row%2==0)
       s = 0;
    else
      s  = 1;

     i=1;
     while(i<=row)
      {
	for(int k = row/2; k<=i; k++)
	    cout<<" ";

	for(j=row; j<=i*2-s; j++)  // column
	 {
	   if(j==row||j==i*2-s||i==row)
	     cout<<"*";
	   else
	     cout<<" ";
	 }
	cout<<endl;
	i++;
      }

   getch();
 }
OUTPUT:-
Enter size: 9

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

10. Create a Rectangle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int i,j,row;
   clrscr();
   cout<<"Enter Number of rows: "; cin>>row;

       i=1;
       while(i<=row)
	{
	  for(j=1; j<=row; j++)
	   {
	     if(i==1)
		cout<<"*";

	     else if((j==1)||(j==row)|| (i==row))
	      cout<<"*";
	     else
	      cout<<" ";

	  } i++;
	 cout<<endl;
     }

    getch();
  }
OUTPUT:-

Enter Number of rows: 5

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

11. Create a Square in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int i,j,row;
   clrscr();
   cout<<"Enter Number of rows: "; cin>>row;

    for(i=1; i<=row; i++)
     {
       int j=1;
       while(j<=row*2)
	{
	  if((i==1)||(i==row))
	      cout<<"*";

	  else if((j==1)||(j==row*2))
	      cout<<"*";
	  else
	      cout<<" ";
	 j++;
       }

       cout<<endl;
     }
    getch();
  }
OUTPUT:-

Enter Number of rows: 5
**********
*        *
*        *  
*        *  
**********

12. Create Hexagon in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   cout<<endl;

   int upper = row;

//upper part
     for(i=1;i<upper;i++)
       {
	 for(j=1;j<=upper-i;j++)
	   cout<<" ";

	 for(k=1; k<=i*2-1; k++)
	  {
	    if(i<=upper/2)
	       cout<<" ";
	    else if(i==(upper/2)+1)
	       cout<<"*";
	    else if(k==1|| k==i*2-1)
	       cout<<"*";
	    else if(i==upper-1)
	       cout<<" ";
	    else cout<<" ";
	  }
	 cout<<endl;
      }

//lower part
   int lower=row; int col;

    if(lower%2==0)   //check given number even or odd
      col = (lower/2)-1;
   else
      col = (lower/2);

   for(i=1;i<=lower;i++)
     {
       for(j=1;j<=i+1;j++)
	   cout<<" ";

       for(k=1; k<=(lower-i)*2-3; k++) { if(i>=col)
	       cout<<" ";
	    else if(i==col-1)
	       cout<<"*";
	    else if(k==1|| k==(lower-i)*2-3)
	       cout<<"*";
	    else if(i==lower-1)
	       cout<<" ";
	    else cout<<" ";
       }
       cout<<endl;
     }
   getch();
 }
OUTPUT:-
 Enter the number: 8

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

13. Create more than one Pyramids in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,k,l,row,column;
    clrscr();
    cout<<"Enter Height of Pyramid: "; cin>>row;
    cout<<"Enter Number of Pyramid: "; cin>>column;

      for(i=0;i<=row;i++)
       {
	 int t=0;
	 while(t!=column)
	  {
	     for(j=0;j<row-i;j++)
		cout<<" ";

	     for(k=1;k<=i*2-1;k++)
		cout<<"*";

	     for(l=1;l<=row-i;l++)
		cout<<" ";

	     t++;
	  }
	 cout<<endl;
       }

   getch();
 }
OUTPUT:-
Enter Height of Pyramid: 5
Enter Number of Pyramid: 6  
                                                                                
    *        *        *        *        *        * 
   ***      ***      ***      ***      ***      *** 
  *****    *****    *****    *****    *****    *****
 *******  *******  *******  *******  *******  *******
******************************************************

13. Create more than one  Triangles in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,k,l,row,column;
    clrscr();
    cout<<"Enter Height of Pyramid: "; cin>>row;
    cout<<"Enter Number of Pyramid: "; cin>>column;

      for(i=0;i<=row;i++)
       {
	 int t=0;
	 while(t!=column)
	  {
	     for(j=0;j<row-i;j++)
		cout<<"  ";

	     for(k=1;k<=i*2-1;k++)
	      {
		if(k==1||k==i*2-1)
		    cout<<"* ";
		else if(i==row)
		    cout<<"* ";
		else
		    cout<<"  ";
	      }

	     for(l=1;l<=row-i;l++)
		cout<<"  ";
	     t++;
	  }
	 cout<<endl;
       }
   getch();
 }
OUTPUT:-
Enter Height of Pyramid: 4
Enter Number of Pyramid: 4
                                                                                
      *             *             *             *
    *   *         *   *         *   *         *   *
  *       *     *       *     *       *     *       *
* * * * * * * * * * * * * * * * * * * * * * * * * * * *

14. Create Reverse To straight Pyramid in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int row,i,k,l,j;
    clrscr();
    cout<<"Enter row of NumberX2: "; cin>>row;

    cout<<endl;

 //upper part
     for(i=1; i<=row;i++)
      {
	for(j=1; j<i;j++)
	  cout<<" ";

	for(k=1; k<=row-i+1; k++)
	  cout<<"*"; for(l=row-i;l>=1;l--)
	  cout<<"*";

	cout<<endl;
      }


 //lower part
    for(i=1; i<=row; i++)
     {
	for(j=1; j<=row-i; j++)
	    cout<<" ";

	for(k=1; k<=i; k++)
	    cout<<"*"; for(l=i-1;l>=1;l--)
	    cout<<"*";

	cout<<endl;
     }

   getch();
 }
OUTPUT:-
Enter row of NumberX2: 5
                                                                                
********* 
 ******* 
  *****
   ***
    * 
    * 
   *** 
  ***** 
 ******* 
*********

15. Create Right-Angle from Left and Right side 

#include<iostream.h>
#include<conio.h>

 void main()
  {
    int n,i,j,k,l;
    clrscr();
    cout<<"Enter row of length: "; cin>>n;

    cout<<endl;

     for(i=1;i<=n;i++)
      {
	 for(j=1;j<=i;j++)
	    cout<<"*";

	 for(k=i;k<=n+n-i;k++)
	    cout<<" "; for(l=i;l>=1;l--)
	    cout<<"*";

	 cout<<endl;
      }

    getch();
 }
OUTPUT:-
Enter row of length: 5
                                                                            
*         *
**       **
***     ***
****   ****
***** *****

16. Create a Straight and Reverse Right-Angle in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,row;
    clrscr();
    cout<<"Enter the number: "; cin>>row;

    cout<<endl;

    for(i=1;i<=row;i++)
     {
       for(j=1;j<=i;j++)
	  cout<<"*";

       cout<<endl;
     }

    for(i=1;i<=row;i++)
     {
       for(j=1;j<row+1-i;j++)
	  cout<<"*";

       cout<<endl;
     }

   getch();
 }
OUTPUT:-
Enter the number: 5
                                                                                
*
**
***
****
*****
****
***
**
*

17. Create a Butterfly Pattern in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
    int i,j,row;
    clrscr();
    cout<<"Enter size: "; cin>>row;

    cout<<endl;

//upper part
     for(i=1;i<=row;i++)
      {
	 for(j=1; j<=i; j++)
	   cout<<"*"; for(int k=row*2; k>i+j-2; k--)
	   cout<<" ";

	 for(j=1; j<=i; j++)
	   cout<<"*";

	 cout<<endl;
      }

// lower part
     for(i=1; i<=row; i++)
      {
	 for(j=1; j<=row-i; j++)
	     cout<<"*";

	 for(int k=0; k<=(i*2); k++)
	     cout<<" ";

	 for(j=1; j<=row-i; j++)
	     cout<<"*";

	 cout<<endl;
      }
   getch();
 }
OUTPUT:-
Enter size: 5

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

18. Create a Diamond Pattern in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   cout<<endl;

//upper part
     for(i=1;i<row;i++)
       {
	 for(j=1;j<=row-i;j++)
	   cout<<" ";

	 for(k=1; k<=i*2-1; k++)
	  {
	    if(i<=row/2)
	         cout<<" ";
	    else if(i==(row/2)+1) 
                 cout<<"*";
	   else if(k==1|| k==i*2-1)
	         cout<<"*";
	   else if(i==row-1) 
                 cout<<" ";
	   else 
                 cout<<" ";
	  }
	cout<<endl;
      }

//lower part
   for(i=1;i<=row;i++)
     {
       for(j=1;j<=i+1;j++)
	   cout<<" ";

       for(k=1; k<=(row-i)*2-3; k++) { if(i>=(row/2)-1) 
             {
	       if(k==1||k==(row-i)*2-3) 
                      cout<<"*"; 
                else 
                      cout<<" ";
             }
          else  if(k==1 || k==(row-i)*2-3)
	      cout<<"*";
	  else
	      cout<<" ";
	 }
       cout<<endl;
     }
   getch();
 }
OUTPUT:-
Enter the number: 9

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

20. Create Lattu in C++

#include<iostream.h> 
#include<conio.h>

 void main()
  {
   int row,i,j,k;
   clrscr();
   cout<<"Enter the number: "; cin>>row;

   cout<<endl;

   int upper = row;
//upper part
     for(i=1;i<upper;i++)
       {
	 for(j=1;j<=upper-i;j++)
	   cout<<" ";

	 for(k=1; k<=i*2-1; k++)
	  {
	    if(i<=upper/2)
	       cout<<" ";
	    else if(i==(upper/2)+1)
	       cout<<"*";
	    else if(k==1|| k==i*2-1)
	       cout<<"*";
	    else if(i==upper-1)
	       cout<<" ";
	    else cout<<" ";
	  }
	 cout<<endl;
      }

//lower part

   int lower=row;
   for(i=1;i<=lower;i++)
     {
       for(j=1;j<=i+1;j++)
	   cout<<" ";

       for(k=1; k<=(lower-i)*2-3; k++)
	   cout<<i;
	 
       cout<<endl;
     }
   getch();
 }
OUTPUT:-
Enter the number: 9

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

other are,

Basic Pattern list in C++ are:

Basic Patterns list in C++

Interested in pattern view Ashish Pandey’blog defficultcoding.com