[ create a new paste ] login | about

Link: http://codepad.org/Zih2SaQg    [ raw code | output | fork ]

C, pasted on Dec 13:
#include <stdio.h>
#define rows 3
#define cols 7

int  main(void) {
  int r, c, r1, c1, r2, c2, n, icols;
  float tmp[rows];
  float mat[rows][cols] = {
        { 0.5f, 1.4f, 0.5f, 3.1f, 1.4f, 1.4f, 3.1f },
        { 0.5f, 1.4f, 0.5f, 3.1f, 1.4f, 1.4f, 3.1f },
        { 0.5f, 1.4f, 0.5f, 3.1f, 1.4f, 1.4f, 3.1f }
  };

  icols = n = 0;
  for(c = 0; c < cols - icols; c++) {
      for(r = 0; r < rows; r++)
          tmp[r] = mat[r][c];
      for(c1 = c + 1; c1 < cols - icols; c1++) {
         for(r1 = 0; r1 < rows; r1++) {
             if(mat[r1][c1] == tmp[r1]) 
                   n++;
         } 
         if(n == rows) {
             for(c2 = c1; c2 < cols - 1 - icols; c2++) {
                 for(r2 = 0; r2 < rows; r2++)
                      mat[r2][c2] = mat[r2][c2 + 1];
             }
             --c1;
             ++icols;
         }
         n = 0;
     }
  }

  for(r = 0; r < rows; r++) {
     for(c = 0; c <  cols - icols; c++)
         printf("%.1f  ", mat[r][c]);
     putchar('\n');
  }
  return 0;
}


Output:
1
2
3
0.5  1.4  3.1  
0.5  1.4  3.1  
0.5  1.4  3.1  


Create a new paste based on this one


Comments: