int main() {
array double complex a[3][3] = {complex(1,2), 2, 3,
4, 5, 6,
7, 8, 9};
array double complex a2[4][3] = {1, 2, 3,
4, 5, 6,
7, 8, 9,
4, 4, 4};
int n = min(4,3), k = 1;
array double complex d[n], d2[n-(abs(k))];
d = cdiagonal(a);
printf("cdiagonal(a) = %f\n", d);
d = cdiagonal(a2);
printf("cdiagonal(a2) = %f\n", d);
d2 = cdiagonal(a, k);
printf("cdiagonal(a, 1) = %f\n", d2);
d2 = cdiagonal(a2, k);
printf("cdiagonal(a2, 1) = %f\n", d2);
k = -1;
d2 = cdiagonal(a, k);
printf("cdiagonal(a, -1) = %f\n", d2);
d2 = cdiagonal(a2, k);
printf("cdiagonal(a2, -1) = %f\n", d2);
}

cdiagonal(a) = complex(1.000000,2.000000) complex(5.000000,0.000000) complex(9.000000,0.000000)
cdiagonal(a2) = complex(1.000000,0.000000) complex(5.000000,0.000000) complex(9.000000,0.000000)
cdiagonal(a, 1) = complex(2.000000,0.000000) complex(6.000000,0.000000)
cdiagonal(a2, 1) = complex(2.000000,0.000000) complex(6.000000,0.000000)
cdiagonal(a, -1) = complex(4.000000,0.000000) complex(8.000000,0.000000)
cdiagonal(a2, -1) = complex(4.000000,0.000000) complex(8.000000,0.000000)