- C
- C++
- Java
- C#
- Python
C
#include <stdio.h>
int main()
{
int n = 4;
int total = (n * (n + 1) / 2);
int px = 1,py;
int i,j;
for(i = 1; i <= n; i++)
{
py = total - (n - i);
for (j = 1; j <= n * 2; j++)
{
if (j > 2 * (i - 1))
{
if (j <= (n * 2) / 2 + i - 1)
{
printf("%2d ", px++);
}
else
{
printf("%2d ", py++);
}
}
}
printf("\n");
total = total - (n - i + 1);
}
return 0;
}