Assuming you need produce this pattern (a dot stands for a space)
....*
...*.
..*..
.*...
*....
the following code would do:
int n = 5;
for (int row = 0; row < n; ++row)
{
for (int col = 0; col < n; ++col)
{
cout << ((n-col == row+1) ? '*' : '.');
}
cout << endl;
}
For
*....
.*...
..*..
...*.
....*
use
int n = 5;
for (int row = 0; row < n; ++row)
{
for (int col = 0; col < n; ++col)
{
cout << ((col == row) ? '*' : '.');
}
cout << endl;
}
For
....*
....*
....*
....*
....*
use
int n = 5;
for (int row = 0; row < n; ++row)
{
for (int col = 0; col < n; ++col)
{
cout << ((col == n-1) ? '*' : '.');
}
cout << endl;
}
etc.
Cheers
Andi