Reverse character triangle




In this we are going to see a program to print the Reverse Character Triangle in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <stdio.h>
#include <conio.h>


void main()
{
    int rows;
    char c = 'A', a;
    cout << "Enter number of rows: ";
    cin >> rows;

    for (int i = rows; i >= 1; --i)
    {
        char c = 'A';
        for (int space = 0; space < rows - i; ++space)
            cout << "  ";

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

        cout << endl;
    }
    getch();
    clrscr();
}


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

int main()
{
    int rows;
    char c = 'A', a;
    cout << "Enter number of rows: ";
    cin >> rows;

    for (int i = rows; i >= 1; --i)
    {
        char c = 'A';
        for (int space = 0; space < rows - i; ++space)
            cout << "  ";

        for (int j = i; j <= 2 * i - 1; ++j)
        {
            cout << c << " ";
            c++;
        }
        a = c;
        a--;
        for (int j = 0; j < i - 1; ++j)
        {
            a--;
            cout << a << " ";
        }

        cout << endl;
    }

    return 0;
}



#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post