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