Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void mLine (char ch1, char ch2);
- void Triangle(char ch1, char ch2) {
- // Last line should have no spaces in it
- static int spaceCounter = 0;
- if (ch1 < ch2) {
- // The previous line should have one extra space
- spaceCounter ++;
- Triangle(ch1, ch2 - 1);
- }
- // Display our spaces
- mLine(' ', spaceCounter);
- // Display our letters
- mLine(ch1, ch2);
- spaceCounter --;
- cout << "\n";
- }
- void mLine(char ch1, char ch2) {
- // Handle our space recursion
- if(ch1 == ' ') {
- // If we still have spaces left
- if(ch2 != 0) {
- cout << ch1;
- mLine(ch1, ch2 - 1);
- }
- }
- else if(ch1 <= ch2) {
- cout << ch1;
- mLine(ch1 + 1, ch2);
- if(ch1 < ch2)
- cout << ch1;
- }
- }
- int main() {
- Triangle ('a', 'm');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment