We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Printing Pattern Using Loops
Printing Pattern Using Loops
Sort by
recency
|
1034 Discussions
|
Please Login in order to post a comment
Hmmm, IMHO the tests suit machinery use to validate output (in the assert stage), could be improved using patterns, to discard whites character, specially if we use format string to justify the out put it fails.
printf ("%5d", np);
include
include
include
include
int main() {
int min = 0; for (int i = 1; i <= 2 * n - 1; i++) { for (int j = 1; j <= 2 * n - 1; j++) { int a = i; if (i > n) a = 2 * n - i; int b = j; if (b > n) b = 2 * n - j; if (a < b) min = a; else min = b;
}
There were definitely better ways to accomplish this...
There were definitely better approaches but this got the job done...
}`
Most solution I see starts for loops from 0 or 1. Go out of the box and start the for loop from negative. It's easier to understand.