Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <cstdio>
int main(){
int n; scanf("%d", &n);
for(int row = 0; row <= 2*n ; row++){
for(int col = 0; col <= 2*n; col++){
int modRow = std::min(row, 2*n - row);
if(col >= n - modRow && col <= n + modRow){printf("%d ", std::min(col + modRow - n, n + modRow - col));}
else{printf(" ");}
}
printf("\n");
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
0 1 0
0 1 2 1 0
0 1 0
0
Demonstration
Codeforces Solution-B. Present from Lena-Solution in C, C++, Java, Python