/* Written by: -- John L. Weatherwax 2006-05-30 email: wax@alum.mit.edu Please send comments and especially bug reports to the above email address. ----- */ #include "ind2sub.h" /* A block row version -- compatable with C's conventions if M=4 & N=3 then given an index (the first number in the below) this routine returns the paired number below 0=(0,0) 1=(0,1) 2=(0,2) 3=(1,0) 4=(1,1) 5=(1,2) 6=(2,0) 7=(2,1) 8=(2,2) 9=(3,0) 10=(3,1) 11=(3,2) */ void ind2sub(int M, int N, int ind, int *i, int *j){ *j = ind % N; *i = (ind-(*j)) / N; } void test_ind2sub(void){ int M,N,ind,i,j; M=4; N=3; for( ind=0; ind < 12; ind++ ){ ind2sub(M,N,ind,&i,&j); printf("ind=%d; (i,j)=(%d,%d)\n",ind,i,j); } }