mercredi 18 février 2015

How to do a desk check for a pattern in c++?


void prob2(int n)
{
int c, c2, temp = n;
for (c = 0; c <= (n + 1) / 2; c++)
{
for (c2 = 0; c2 < temp; c2++)
cout << " ";
temp--;
for (c2 = 0; c2 < 2 * c - 1; c2++)
{
cout << "* ";
}
cout << "\n";
}
}


For example, if n=5, this code draws a triangle:



*
* * *
* * * * *

My problem is that since I don't understand the procedure, I can't use the thought process behind this code to create the same triangle rotated to the right/flipped/etc.



*
* *
* * *
* *
*

*
* *
* * *
* *
*

Aucun commentaire:

Enregistrer un commentaire