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.
int size = 2 * n - 1;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
for (int k = 0; k < n; k++) {
if (i == k || i == size - k - 1 || j == k || j == size - k - 1) {
printf("%d ", n - k);
break;
}
}
}
printf("\n");
}
just going layer by layer
if(i == k || ...
print...
break; // this is the most important part cause it only allows one layer at a time
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
Simple Understandable Approach
just going layer by layer
if(i == k || ...
print...
break; // this is the most important part cause it only allows one layer at a time