Pattern Program list in C++

PATTERNS PROGRAMS IN C++

Here in this Page you found all Pattern Program list in C++, which are divided into two category Basic Patterns in C++ and Complex Patterns in C++,

But make before creating patterns in C++ you read create patterns in C++ you can also view ashish Pandey ‘s Blog defficultcoding.com where he will teach you about patterns programs in C++

Let’s start here,

Basic Pattern Program list in C++


1. Create a Rectangle of Number of Ascending Order in C++

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

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

     i=1;
     while(i<=row) // row
       {
         for(j=1; j<=row; j++)  // column
	    {
	       cout<<" "<<j;    
	    }
	    cout<<endl;
	    i++;
       }

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

 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

2.Create a Square of Numbers of Ascending and Descending Order in C++

#include<iostream.h>
#include<conio.h> void main() { int row,i,j; clrscr(); cout<<"Enter number of row: "; cin>>row; cout<<endl; i=1; while(i<=row) // row of number { if(i%2!=0) { for(j=1; j<=row+1; j++) cout<<" "<<j; } else { for(j=row; j>=0; j--) cout<<" "<<j; } cout<<endl; i++; } getch(); }
OUTPUT:-
Enter number of row: 5

 1 2 3 4 5 6
 5 4 3 2 1 0
 1 2 3 4 5 6
 5 4 3 2 1 0
 1 2 3 4 5 6

3.Create a Right-Angle of Numbers of Descending Order as Horizontally

#include<iostream.h>
#include<conio.h> void main() { int row,i,j; clrscr(); cout<<"Enter the number: "; cin>>row; for(i=row; i>=1; i--) // row { for(j=row; i<=j; j--) // column { cout<<" "<<j; } cout<<endl; } getch(); }
OUTPUT:-

Enter the number: 5
 5  
 5 4 
 5 4 3
 5 4 3 2
 5 4 3 2 1

4.Create a Right-Angle of Numbers of Ascending Order as Vertically

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

 1
 2 2
 3 3 3
 4 4 4 4
 5 5 5 5 5

5.Create a Right-Angle of Numbers of Ascending Order from Right-side

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j,k; clrscr(); cout<<"Enter the number: "; cin>>row; cout<<endl; for(i=1;i<=row;i++) { for(j=1;j<=row-i;j++) cout<<" "; for(k=1; k<=i; k++) cout<<k; cout<<endl; } getch(); }
OUTPUT:-
Enter number of row: 5
           
         1
       1 2
     1 2 3
   1 2 3 4
 1 2 3 4 5

6. Create a Reverse Right-Angle of Numbers from Right-side

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j,k; clrscr(); cout<<"Enter Number of rows: "; cin>>row; cout<<endl; for(i=1;i<=row;i++) { for(j=1;j<=i;j++) cout<<" "; for(k=1; k<=row-i; k++) cout<<k; cout<<endl; } getch(); }
OUTPUT:-
Enter Number of rows: 6

   1 2 3 4 5
     1 2 3 4
       1 2 3
         1 2
	   1

7. Create a Reverse Right-Angle of Numbers from Left-side

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j; clrscr(); cout<<"Enter the number: "; cin>>row; for(i=row; i>=1; i--) // row { for(j=1; j<=i; j++) // column 5>=1 1<=j { cout<<" "<<j; } cout<<endl; } getch(); }
OUTPUT:-

Enter the number: 5
 1 2 3 4 5  
 1 2 3 4
 1 2 3
 1 2
 1

8. Create a Reverse Right-Angle of Descending Numbers as Horizontally from Left-side

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j; clrscr(); cout<<"Enter the number: "; cin>>row; for(i=1; i<=row; i++) // row { for(j=row; i<=j; j--) // column 5>=1 1<=j { cout<<" "<<j; } cout<<endl; } getch(); }
OUTPUT:-

Enter the number: 5
 5 4 3 2 1 
 5 4 3 2
 5 4 3
 5 4 
 5

9. Create a Reverse Right-Angle of Ascending Numbers as Vertically from Left-side

#include<iostream.h>
#include<conio.h> void main() { int row,x=1; clrscr(); cout<<"Enter the number: "; cin>>row; for(int i=row; i>=1; i--) //for(int i=1;i<=n;i++) { for(int j=1; j<=i; j++) //for(int j=1;j<=n+1-i;j++) { cout<<x<<" "; } cout<<endl; x++; } getch(); }
 OUTPUT:-
Enter the number: 5

 1 1 1 1 1
 2 2 2 2
 3 3 3
 4 4
 5

10. Create a Reverse Right-Angle of Descending Numbers as Vertically from Left-side

#include<iostream.h> 
#include<conio.h> void main() { int row,x=1; clrscr(); cout<<"Enter the number: "; cin>>row; for(int i=row; i>=1; i--) //for(int i=1;i<=n;i++) { for(int j=1; j<=i; j++) //for(int j=1;j<=n+1-i;j++) { cout<<x<<" "; } cout<<endl; x++; } getch(); }
OUTPUT:-
Enter the number: 5

 5 5 5 5 5
 4 4 4 4
 3 3 3
 2 2
 1

11. Create a Complete Right-Angle of only Ascending Number

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j,count=1; clrscr(); cout<<"Enter the number: "; cin>>row; for(i=1; i<=row; i++) // row { for(j=1;j<=i;j++) // column { cout<<" "<<count++; // print j value } cout<<endl; } getch(); }
OUTPUT:-
Enter the number: 5

 1
 2 3
 4 5 6
 7 8 9 10
 11 12 13 14 15

12. Create a Right-Angle of Odd Numbers

#include<iostream.h> 
#include<conio.h> void main() { int row,i,j,count=1; clrscr(); cout<<"Enter the number: "; cin>>row; for(i=1; i<=row; i++) // row { for(j=1;j<=i;j++) // column { cout<<" "<<count; // print j value count=count+2; } cout<<endl; } getch(); }
OUTPUT:-
Enter the number: 5

 1
 3 5 
 7 9 11
 13 15 17 19
 21 23 25 27 29

For even numbers, Only change variable count value to 0, while remaining code will be the same as above code which will print following pattern,

Enter the number: 5

 0
 2 4
 6 8 10
 12 14 16 18
 20 22 24 26 28

13. Create Pyramid of Numbers as Ascending and Descending in C++

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

    1   
   121 
  12321  
 1234321
123454321

14. Create a Right-Angle in Different way using Alphabet Character

#include<iostream.h> 
#include<conio.h> void main() { clrscr(); int count='A',row; cout<<"Enter Number: "; cin>>row; for(int i =1; i<=row; i++) { for(int j=1;j<=i;j++) { cout<<char(count)<<" "; } cout<<endl; count++; } getch(); }
OUTPUT:-
Enter Number: 5

 A
 B B
 C C C
 D D D D
 E E E E E
#include<iostream.h>
#include<conio.h>

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

     for(int i = 0; i<=row; i++)
      {
	cout<<char(count++)<<" ";

	for(int j=1; j<=i; j++)
	 {
	    cout<<char(count++)<<" ";
	 }
	 cout<<endl;
      }

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

 A
 B C
 D E F
 G H I J
 K L M N O
 P Q R S T U

15. Creating a Right-Angle using ASCII code

#include<iostream.h> 
#include<conio.h> void main() { clrscr(); for(int i = 65; i<70; i++) { for(int j=65; j<=i; j++) { cout<<char(j)<<" "; } cout<<endl; } getch(); }
OUTPUT:-
 A
 A B
 A B C
 A B C D
 A B C D E