Student Project
2024-08-26 18:45:28 UTC
This is worth a try to run it in Linux, Windows and MacOS:
<*******************************************>
#include <iostream>
#include <string>
using namespace std;
int main()
{
   string letters;
   cout << "Enter a string to create a pyramid pattern: ";
   // cin >> letters;
   getline(cin, letters);
   int len = letters.length();
   int position = 0;
   for (char c : letters)
   {
       int spaces = len - (position + 1);
       while (spaces > 0)
       {
           cout << " ";
           --spaces;
       }
       for (int i = 0; i < position; i++)
       {
           cout << letters.at(i);
       }
       cout << c;
       for (int i = position - 1; i >= 0; i--)
       {
           cout << letters.at(i);
       }
       cout << "\n";
       position++;
   }
   return 0;
}
<*******************************************>
<*******************************************>
#include <iostream>
#include <string>
using namespace std;
int main()
{
   string letters;
   cout << "Enter a string to create a pyramid pattern: ";
   // cin >> letters;
   getline(cin, letters);
   int len = letters.length();
   int position = 0;
   for (char c : letters)
   {
       int spaces = len - (position + 1);
       while (spaces > 0)
       {
           cout << " ";
           --spaces;
       }
       for (int i = 0; i < position; i++)
       {
           cout << letters.at(i);
       }
       cout << c;
       for (int i = position - 1; i >= 0; i--)
       {
           cout << letters.at(i);
       }
       cout << "\n";
       position++;
   }
   return 0;
}
<*******************************************>