how to concatenate a matrix?

 Alex Nuta · August 26, 2014 Hello, I'm new here and I am also relatively new to c. I have to concatenate a matrix and I don't know how to do that, have searched a little on google but it raises more questions than answes.For example if i have a matrix  [3][3]  and I want do add 0 around the matrix, how do I do that?   the final form should be like:0 0 0 0 00 1 1 1 00 1 1 1 00 1 1 1 00 0 0 0 0 #include int main(){int mat [3][3];int i,j;  for (i=0;i< 3; i++){    for(j=0;j< 3; j++){      scanf("%d", &mat[j]);  }    }................... and now i want to add around mat 0's      ty in advance.return 0;}

Replies

 Alex Nuta · August 26, 2014 EDIT: Thanks to Mathias Frits Rørvik I was able to figure it out, just make another matrix 2x2 bigger and add the 0's I will not delete what I posted below(it was before I read the above post but I was unable to edit it due to the fact that a mod had to approve it before it was posted), maby someone wants to solve it too or something I now see I have done a big mistake not telling you all the details, basicly i'm working on this problem and I have gotten to that point that I have to add an outer layer to the matrix, but I do need to work on a matrix, anyways ill just post the problem so I wont fail with the description againSo I read the matrix and in order to solve it they way I am thinking I need to add 0-s around the matrix and do something like://I got the mat and r-rows c-columnsint counter=0;int maxtime=0;int r=5;int c=6;for (i=1; imaxtime){maxtime=counter;}}}}printf("%d",maxtime); Bucky Roberts · August 26, 2014 This doesn't use a matrix, but it does show you how you can break it up to accomplish what you want to to. It will work for any size matrix.``#include int main(){    int a, i, j;    //the column and row length of the original matrix    int col = 5;    int row = 9;    // print the first row of o's    for(a=-1; a<=col; a++){        printf("o ");    }    printf("\n");    //create the matrix with o's on left and right    for(i=0; i
• 1

C

129,732 followers
About

One of the most popular languages of all time.

Links
Moderators
 Bucky Roberts Administrator