The pattern I need to print out looks like the right and the left side of a triangle combined.
I can print out the right and the left side of a triangle separated but not on the same level. this is how I do it:
#include<iostream>
using std::cout;
int main()
{
for( int row = 0; row < 4; ++row )
{
for ( int col = 0; col <= row; ++col ) {
cout << '*';
}
for ( int space = 0; space < 4 - 2*row; ++space ) {
cout << ' ';
}
for ( int col = 0; col <= row; ++col ) {
cout << '*';
}
cout << '\n';
}
return 0;
}
In fact, I would rather have only one inner loop and calculate a boolean from (row,col). Hint: abs()