c - How to add a border around a matrix? -


i have problem need process matrix toroid calculating sum of neighbours, have thought way: add border around matrix elements represent outline of matrix.to more specific, if had matrix:
1 2 3
4 5 6
7 8 9,
after adding border this:
9 7 8 9 7
3 1 2 3 1
6 4 5 6 4
9 7 8 9 7
3 1 2 3 1
bolded numbers represent initial matrix.note corners of border opposite corner of initial matrix(e.g. :the corner adjacent a11(whose value 1) a00,(whose value 9),the same a33,the corner opposing a11 in initial matrix ). far have come algorithm, pretty works fine, except rightmost column, or think.yes aware algorithm not have complexity, it's best come , have no memory/time restriction on problem.any suggestions error might be?(n number of lines, m number of columns

        (i=1; i<n+1; i++)         {             (j=1; j<m+1; j++)             {                 b[i][j]=a[i][j];             }         }         for(i=1; i<m+1; i++)         {             b[0][i]=b[n][i];             b[n+1][i]=b[1][i];         }         for(j=1; j<n+1; j++)         {             b[i][0]=b[i][m];             b[i][m+1]=b[i][1];         }         b[0][0]=b[n][m];         b[m+1][n+1]=b[1][1];         b[n+1][0]=b[1][m];         b[0][m+1]=b[n][1]; 


p.s.sorry if there grammar/spelling/ errors or ambiguos text, english far perfect if have questions ask them , try explain better.

your last loop iterator 'j' use 'i' index elements.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -