title: How to print backwards column of matrix represented by array in C?
body: <p>I am working on program that takes matrix from input file like this. where first row represents parameters of matrix - rows,cols,0 for changing odd cols and 1 for changing even cols</p>
  
  <pre><code>5 5 0
  1 2 3 4 5
  6 7 8 9 10
  11 12 13 14 15
  16 17 18 19 20
  21 22 23 24 25
  </code></pre>
  
  <p>and now I have to take odd clomuns (example: 7 4 1) and print it backwards so it will look like this ( 1 4 7 ) if I had 3x3 matrix it would looks like:</p>
  
  <pre><code>1 2 3
  4 5 6
  7 8 9
  </code></pre>
  
  <p>output matrix with odd cols printed backwards</p>
  
  <pre><code>7 2 9
  4 5 6
  1 8 3
  </code></pre>
  
  <p>and this is code I have so far</p>
  
  <pre><code>int r = 0, c = 0, odds = 0,n = 0,i,j;
  FILE *fp,*fp2;
  fp = fopen(argv[1],"r");
  fp2 = fopen(argv[2],"w");
  if(!fp){
      printf("file doesnt exist\n");
  }
  if(!fp2){
      printf("file doesnt exist\n");
  }
  fscanf(fp,"%d %d %d", &amp;r, &amp;c, &amp;odds);
  n = r *c;
  int* matrix= (int*)malloc(r*c* sizeof(int));
  
  for(int i = 0; i &lt; n; i++)
  {
      fscanf(fp,"%d",&amp;matrix[i]);
  }
  
  if(odds == 0){
  for(int i = 0; i &lt; n; i++){
  
      if(i%2==0){
      matrix[i] = i;
      }
  }
  }else if(odds == 1){
     for(int i = 0; i &lt; n; i++){
  
      if(i%2!=0){
      matrix[i] =  ;
      }
  } 
  }
  
  
  
  
  for(i = 0;i &lt; n; i++)
  {    
          if(i % s == 0 ){
          fprintf(fp2,"\n");
          }
          fprintf(fp2,"%d ",matrix[i]);
  
  
  
  }
      fclose(fp);
      fclose(fp2);
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>and my problem is with backwarding the cols, which is supposed to happen here</p>
  
  <pre><code>if(odds == 0){
  for(int i = 0; i &lt; n; i++){
  
      if(i%2==0){
      matrix[i] = i;
      }
  }
  }else if(odds == 1){
     for(int i = 0; i &lt; n; i++){
  
      if(i%2!=0){
      matrix[i] =  ;
      }
  } 
  }
  </code></pre>
  
  <p>1st if is for printing even cols backwards and 2nd is for odd cols
  and as you can see the matrix is in my program represented by normal array
  which wasn't my idea, but teachers, so its supposed to work like this</p>
  
  <pre><code>1 2 3|4 5 6|7 8 9  ----&gt; 7 2 9|4 5 6|1 8 3
  </code></pre>
  
  <p>ok I just found out about map indexing, so now each position in array is presented as matrix[j+(i*r)] so for example 1st position in the 3x3 matrix above would be something like this: matrix[1+(0*3)], 4th pos would be matrix[1+(1*3)] etc... </p>
  
  <p>So now my question is how to index the opposite postion in the column.</p>
  
  <p>code update:</p>
  
  <pre><code>for(int i = 0; i &lt; r; i++){
  
      for(int j = 1; j &lt; c; j++){
          if(i%2!=0){
              matrix[j+i*r] = ....;
      }
  
  }
  }
  </code></pre>