Hard Light Productions Forums
Off-Topic Discussion => Programming => Topic started by: Kosh on November 22, 2008, 05:33:28 am
-
Our assignment is to make the following to appear on screen:
*
* * *
* * * * *
* * * * * * *
* * *
* * *
* * *
Other than brute forcing it, is there another way with loops? I was thinking nested loops but I'm not entirely clear on how to increment this.....
-
Try thinking about how the number of *s per line changes as you go down and also the number of spaces before the *s start on each line. Of course, this is only worth doing if the arrow size is variable; otherwise, you might as well just print a string literal.
-
#include <iostream>
int main()
{
cout << " *\n
* * *\n
* * * * *\n
* * * * * * *\n
* * *\n
* * *\n
* * *\n";
return 0;
}
If an assignment is only going to take you 15 seconds to brute force, you might as well brute force it.
-
Thanks.