Skip to content

triangle rectangle upper_triangle lower_triangle, reverse_triangle, upper_rectanlge, lower_rectangle, reverse_rectangle

Notifications You must be signed in to change notification settings

Anower77/All-Type-Patterns-C-plus-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. Program to print half pyramid using alphabets (Vertical)

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int row, col, n;
    cout<< "Enter Integer Number : ";
    cin>> n;

    for(row = 1; row <= n; row++){

        for(col = 1; col <= row; col++){

            cout<< " " << char(col+64) ;/// char(col+96) it's return small letter

        };
        cout<<endl;
    };


    getch();
}

Input : 10


Output -

 

2. Program to print half pyramid using alphabets (Horizontal)

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int row, col, n;
    cout<< "Enter Integer Number : ";
    cin>> n;

    for(row = 1; row <= n; row++){

        for(col = 1; col <= row; col++){

            cout<< " " << char(row+64) ;/// char(row+96) it's return small letter

        };
        cout<<endl;
    };


    getch();
}

Input : 10


Output -

 

3. Print Floyd's Triangle (Binary Number)

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int row, col, n;

    cout<< "Enter Integer Number : ";
    cin>> n;

    for(row = 1; row <= n; row++){

        for(col = 1; col <= row; col++){

            cout<< " " << (col%2) ;

        };
        cout<<endl;
    };


    getch();
}

Input : 10


Output -

 



4. Print Floyd's Triangle (Horizontal)

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int row, col, n;

    cout<< "Enter Integer Number : ";
    cin>> n;

    for(row = 1; row <= n; row++){

        for(col = 1; col <= row; col++){

            cout<< " " << (row%2) ;

        };
        cout<<endl;
    };


    getch();
}

Input : 10


Output -

 



5. Inverted top-bottom pyramid using *

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    while (true)
    {
    
    int row, col, n;
    cout<<  "Enter N : ";
    cin>> n;
    for (row = 1; row <= n; row++){

        for(col = 1; col <= row; col++)
        {
            cout<< "* ";
        }
        cout << endl;
    }

    for (row = n-1; row >= 1; row--)
    {

        for (col = 1; col <= row; col++)
        {
            cout<< "* ";
        }
        cout<< endl;
    }

    }
    return 0;
    getch();
}

Input : 10


Output -

 



6. Inverted top-bottom pyramid using Number

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int col, row, n;
    cout<<"Enter Number : ";
    cin>> n;
    /*
    1
    1 2
    1 2 3
    */

    for (row = 1; row <= n; row++){
        for (col = 1; col <= row; col++){
            cout<< " "<<col;
        }
        cout<<endl;
    }
    /*
    1 2 3
    1 2
    1
    */

    for (row = (n-1); row >= 1; row--){
        for (col = 1; col <= row; col++){
            cout<<" "<<col;
        }
        cout<<endl;
    }

    getch();
}

Input : 10


Output -

 



7. Program to print full pyramid using *

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    while(true){


    int n, col, row;
    cout<< "Enter N : ";
    cin>> n;
    for (row = 1; row <= n; row++)
    {

        //Printing spaces
        for (col = 1; col <= n-row; col++)
        {

            cout<< "  ";

        };
        //Printing star
        for (col =1; col <= 2*row-1; col++){

            cout<< "* ";
        };
        cout<< endl;
    }

}//End while loop
    getch();
}

Input : 10


Output -

 



8. Square full pyramid using *

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    while(true){


    int n, col, row;
    cout<< "Enter N : ";
    cin>> n;
    for (row = 1; row <= n; row++)
    {

        //Printing spaces
        for (col = 1; col <= n-row; col++)
        {

            cout<< "  ";

        };
        //Printing star
        for (col =1; col <= 2*row-1; col++){

            cout<< "* ";
        };
        cout<< endl;
    }

    ///Reverse Pyramid
        for (row = n-1; row >= 1; row--)
        {

        //Printing spaces
        for (col = 1; col <= n-row; col++)
        {

            cout<< "  ";

        };
        //Printing star
        for (col =1; col <= 2*row-1; col++){

            cout<< "* ";
        };
        cout<< endl;
    };

}//End while loop
    getch();
}

Input : 10


Output -

 



9. Inverted half pyramid using Numbers

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int row, col, n;
    cout<< "Enter Integer Number : ";
    cin>> n;

    for(row = n; row >= 1; row--){

        for(col = 1; col <= row; col++){

            cout<< " " << row;
        };
        cout<<endl;
    };


    getch();
}


Input : 9


Output -

 



10. Program For Rectangle And Square Star Pattern

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
while(1){
    int n, col, row;
    cout<<"Enter Number : ";
    cin>>n;
    for (row = 1; row <= n; row++)
    {

        ///spacing
        for (col = 1; col <= n-row; col++)
        {
            cout<< " ";
        }
        ///number
        for (col = 1; col <= row; col++)
        {
            cout<<char(col+64) ;//col
        }
        cout<< endl;
    }
}

    getch();
}

Input : 10


Output -

10. Program To Print Hollow Rectangle Or Square Star Pattern

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int rows,columns,i,j;
    cout<<"Enter the number of rows : ";
    cin>>rows;
    cout<<"Enter the number of columns : ";
    cin>>columns;
    for (i=1; i<=rows; i++){
    for (j=1; j<=columns; j++){
    if(i==1||i==rows||j==1||j==columns){
        cout<<"*";
    }else{
        cout<<" ";
    }
}
    cout<<endl;
}
    return 0;
}

Input : 10 & 20


Output -

About

triangle rectangle upper_triangle lower_triangle, reverse_triangle, upper_rectanlge, lower_rectangle, reverse_rectangle

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages