I think something like this will produce the correct string for each iteration. Looping over that would get the series. It may not be 100%, but its a starting point. You will have to figure out mid and max.
char curr = 'A';
for(i = 0; i < mid; i++)
output[i] = curr++;
for(i = mid; i < max; i++)
output[i] = curr--;
for(i = 0; i < iteration; i++) //assuming iteration 0 is the full string, start at 1 to remove mid, etc...
{
output[mid+i] = ' ';
output[mid-1] = ' ';
}
Do this one piece at a time. I started by figuring how to print the top line. One trick with problems like this is to run your counter from, say, -6 to 6 and then use the abs() function to get a value that goes from 6 to zero and back to 6:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n, i;
cout << "Enter number of lines :\n";
cin >> n;
--n; // it's easier to work with this
for (i = -n; i <= n; ++i) {
char ch = 'A' + n - abs(i);
cout << ch;
}
cout << '\n';
}
This method also makes printing the spaces a lot easier too. Let's number the lines 0-6. At line #L, you print a space when abs(i) < L. Otherwise you print the character given above.