C++ Online Compiler
Example: Alphabet Palindrome Pyramid in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Alphabet Palindrome Pyramid #include <iostream> using namespace std; int main() { int rows; cout << "Enter the number of rows for the alphabet palindrome pyramid: "; cin >> rows; // Outer loop for rows for (int i = 0; i < rows; ++i) { // Step 1: Print leading spaces for (int space = 0; space < rows - i - 1; ++space) { cout << " "; // Two spaces for alignment } // Step 2: Print ascending alphabets char currentAlphabet = 'A'; for (int j = 0; j <= i; ++j) { cout << (char)(currentAlphabet + j) << " "; } // Step 3: Print descending alphabets (excluding the peak character) for (int j = i - 1; j >= 0; --j) { cout << (char)(currentAlphabet + j) << " "; } cout << endl; // Move to the next line after each row } return 0; }
Output
Clear
ADVERTISEMENTS