Linear Algebra and the C Language/a055


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as : swapc.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{
double a[R3*C3] ={  1,    2,    3, 
                    1,    2,    3, 
                    1,    2,    3};

double **A = ca_A_mR(a,i_mR(R3,C3));

int c1 = C1;
int c2 = C3;
  
 clrscrn();
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 printf(" swapC_mR(A, C%d, C%d)\n\n",c1,c2);
 
 printf(" A :");
 p_mR(swapC_mR(A,c1,c2),S5,P0,C6);

 f_mR(A);

 stop();
 
 return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Swaps two columns:

Screen output example:

 A :
   +1    +2    +3 
   +1    +2    +3 
   +1    +2    +3 

 swapC_mR(A, C1, C3)

 A :
   +3    +2    +1 
   +3    +2    +1 
   +3    +2    +1 

 Press return to continue.