/*
numeric diamond algorithm..
not sure if this is the fastest algorithm
novatech - http://wan.pengganas.net
*/
#include <stdio.h>
#include <math.h>
void diamond(int size) {
int i,j,k,x;
x = sqrt(size);
int left,right=-1*x+1;
for (i = 1; i < x*2 ;i++)
{
left = (i>x)?x*2-i:i;
for (k=0;k<=x-left;k++) printf(" ");
right = (i>x)?right+1:right+x;
printf("%d",right);
for (j = 1;j < left;j++) {
printf(" %d",right-(x-1)*j);
}
printf("\n");
}
}
int main() {
//input must be n^2
diamond(9);
diamond(36);
diamond(100);
diamond(121);
return 0;
}