Pattern Printing

1. Right Half Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    for (int r = 1; r <= 5; r++)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << " * ";
        }
        cout << endl;
    }
    
    return 0;
}


Output:

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




2. Number Increasing Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
    for (int r = 1; r <= 5; r++)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << c << "  ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




3. Number Repeating Triangle

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
 
    for (int r = 1; r <= 5; r++)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << r << "  ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




4. Reverse Floyd's Triangle

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
 
    for (int r = 1; r <= 5; r++)
    {
        for (int c = r; c >= 1; c--)
        {
            cout << c << "  ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




5. Alphabet Right Traingle

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
 
    char ch = 'a';
    for (int r = 1; r <= 5; r++)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << ch << "  ";
        }
        cout << endl;
        ch ++;
    }
 
    return 0;
}


Output:

a b b c c c d d d d e e e e e




6. Reversed Right Half Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    for (int r = 5; r >= 1; r--)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << " * ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




7. Inverted Number Traingle

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
 
    for (int r = 5; r >= 1; r--)
    {
        for (int c = 1; c <= r; c++)
        {
            cout << c << "  ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




8. Decreasing Reversed Number Traingle

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main()
{
 
    for (int r = 5; r >= 1; r--)
    {
        for (int c = 5; c >= r; c--)
        {
            cout << c << "  ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




9. Left Half Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (int c = 1; c <= r; c++)
        {
            cout << "* ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




10. Left Half Number Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (int c = 1; c <= r; c++)
        {
            cout << r << " ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




11. Left Half Increasing Number Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (int c = 1; c <= r; c++)
        {
            cout << c << " ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




12. Left Half Increasing Character Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        char ch = 'a';
        for (char c = 1; c <= r; c++)
        {
            cout << ch << " ";
            ch++;
        }
        cout << endl;
    }
 
    return 0;
}


Output:

  a   a b   a b c   a b c d  a b c d e




13. Left Half Repeating Character Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    char ch = 'a';
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (char c = 1; c <= r; c++)
        {
            cout << ch << " ";
        }
        cout << endl;
        ch++;
    }
 
    return 0;
}


Output:

  a   b b   c c c   d d d d  e e e e e




14. Left Half Decreasing Number Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (int c = r; c >= 1; c--)
        {
            cout << c << " ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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




15. Full Star Pyramid

Code:

code.cpp
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n = 5;
    for (int r = 1; r <= n; r++)
    {
        for (int c = 1; c <= n - r; c++)
        {
            cout << "  ";
        }
 
        for (int c = 1; c <= 2 * r - 1; c++)
        {
            cout << "* ";
        }
        cout << endl;
    }
 
    return 0;
}


Output:

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