C++ program to print Reverse Pyramid with alphabets


Following C++ program builds reverse pyramid pattern with alphabets using for loop

#include <iostream>
using namespace std;

int main() {
  int rows=6, j;
  char alphabet = 'A';

  if (rows > 0) {
    cout << endl;
    for (int i = rows; i >= 1; i--) {
      for (int leet = 0; leet < rows - i; leet++)
        cout << "  ";
      for (j = i; j <= 2 * i - 1; j++)
        cout << alphabet << " ";
      for (j = 0; j < i - 1; j++)
        cout << alphabet << " ";
      alphabet++;
      cout << endl;
    }
  }
  
  return 0;
}

Output:


A A A A A A A A A A A 
  B B B B B B B B B 
    C C C C C C C 
      D D D D D 
        E E E 
          F 

Try it Online here https://onecompiler.com/cpp/3x73t8u6t