OneCompiler

Print the following pattern : A A B C A B C D E A B C D E F G A B C D E A B C A

#include <iostream>
using namespace std;

void printPattern() {
char ch = 'A';
int n = 7; // Total number of lines in the pattern

// Print the upper part of the pattern
for (int i = 1; i <= n; i += 2) {
    for (int j = 0; j < i; j++) {
        cout << char(ch + j) << " ";
    }
    cout << endl;
}

// Print the lower part of the pattern
for (int i = n - 2; i >= 1; i -= 2) {
    for (int j = 0; j < i; j++) {
        cout << char(ch + j) << " ";
    }
    cout << endl;
}

}

int main() {
printPattern();
return 0;
}