-
Notifications
You must be signed in to change notification settings - Fork 137
Open
Description
int main()
{
int n;
scanf("%d", &n);
// The size of the grid is (2*n - 1)
int len = 2 * n - 1;
// Iterate through rows
for(int i = 0; i < len; i++) {
// Iterate through columns
for(int j = 0; j < len; j++) {
// Calculate distance to all four edges
int min = i;
if (j < min) min = j;
if (len - 1 - i < min) min = len - 1 - i;
if (len - 1 - j < min) min = len - 1 - j;
// Print the value based on the minimum distance
printf("%d ", n - min);
}
// Newline after each row
printf("\n");
}
return 0;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels