Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string getPyramid(const string&);
- int main()
- {
- string letters {""};
- cout << "Give me some letters: ";
- cin >> letters;
- cout << getPyramid(letters);
- }
- string getPyramid(const string &letters)
- {
- string pyramid {""};
- for (int i {0}; i < (int)letters.length(); i++)
- {
- for (int j {0}; j < (int)letters.length() - 1 - i; j++) pyramid += ' '; //spaces
- for (int j {0}; j <= i; j++) pyramid += letters.at(j); //begin to center
- for (int j {i-1}; j >= 0; j--) pyramid += letters.at(j); //center (exclusive) to begin
- pyramid += '\n'; //endline
- }
- return pyramid;
- }
Add Comment
Please, Sign In to add comment