home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / MAELEM.C < prev    next >
Encoding:
Text File  |  1984-06-13  |  2.4 KB  |  88 lines

  1.       maelem(lra,nrow,ncol,a,i,j,scalar,iflag)
  2.  
  3.       /*this function is used to do some elementary matrix */
  4.       /*operations on rows or columns.*/
  5.  
  6.       int i,iflag,j,lra,nrow,ncol;
  7.       float a[],scalar;
  8.  
  9.      {
  10.       int ii,ir,is,nflag;
  11.       float c;
  12.  
  13.         nflag = iflag + 48;     /* convert to ASCII */
  14.         switch(nflag) {
  15.         case '1':               /* multiply a row by a constant */
  16.           ir = (i - 1) * lra;
  17.           for(ii = 0; ii <= ncol-1; ii++)
  18.           {
  19.            a[ir] *= scalar;
  20.            ir++;
  21.           };
  22.           break;                /* end of case 1 */
  23.  
  24.         case '2':               /* switch two rows */
  25.           ir = (i - 1) * lra;
  26.           is = (j - 1) * lra;
  27.           for( ii = 0; ii <= ncol-1; ii++)
  28.           {
  29.            c = a[ir];
  30.            a[ir] = a[is];
  31.            a[is] = c;
  32.            ir++ ;
  33.            is++ ;
  34.           };
  35.         break;                  /* end of case 2 */
  36.  
  37.         case '3':               /* add multiple of one row to another */
  38.           ir = (i - 1) * lra;
  39.           is = (j - 1) * lra;
  40.           for( ii = 0; ii <= ncol-1; ii++)
  41.            {
  42.             a[ir] += scalar * a[is];
  43.             ir++;
  44.             is++;
  45.            };
  46.         break;                  /* end of case 3 */
  47.  
  48.         case '4':               /* multiply a column by a constant */
  49.            ir = i - 1;
  50.            for(ii = 0; ii <= nrow-1; ii++)
  51.            {
  52.             a[ir] *= scalar;
  53.             ir += lra;
  54.            };
  55.         break;                  /* end of case 4 */
  56.  
  57.         case '5':               /* switch 2 columns */
  58.            ir = i - 1;
  59.            is = j - 1;
  60.            for(ii = 0; ii <= nrow-1; ii++)
  61.            {
  62.             c = a[ir];
  63.             a[ir] = a[is];
  64.             a[is] = c;
  65.             ir += lra;
  66.             is += lra;
  67.            };
  68.         break;                  /* end of case 5 */
  69.  
  70.         case '6':               /* add multiple of one column to another */
  71.             ir = i - 1;
  72.             is = j - 1;
  73.             for(ii = 0; ii <= nrow-1; ii++)
  74.             {
  75.              a[ir] += scalar * a[is];
  76.              ir += lra;
  77.              is += lra;
  78.             };
  79.         break;                  /* end of case 6 */
  80.  
  81.         default:                /* error message*/
  82.         printf("Case not found for IFLAG= %d\n",iflag);
  83.         break;
  84.  
  85.                       }
  86.      }
  87.  
  88.