home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / MAELEM.TST < prev    next >
Encoding:
Text File  |  1984-08-31  |  3.5 KB  |  127 lines

  1.         /* General form test program for scientific functions */
  2.  
  3.         /* Routine Tested:  MAELEM */
  4.  
  5.         main()
  6.  
  7.         {
  8.         int i,iflag,j,lra,nrow,ncol,ne;
  9.         float a[48],s;
  10.         static float b[48]={2., 3., 4., 5., 6., 7.,
  11.                             3., 4., 5., 6., 7., 8.,
  12.                             4., 5., 6., 7., 8., 9.,
  13.                             5., 6., 7., 8., 9.,10.,
  14.                             6., 7., 8., 9.,10.,11.,
  15.                             7., 8., 9.,10.,11.,12.,
  16.                             8., 9.,10.,11.,12.,13.,
  17.                             9.,10.,11.,12.,13.,14.
  18.                            };
  19.  
  20.  
  21.         lra = 6;
  22.         nrow = 8;
  23.         ncol = 6;
  24.         ne = nrow*ncol;
  25.  
  26.      /* First case, multiply row 4 by the scalar 5.0 */
  27.         afil(a,b,ne);           /* fill array for start */
  28.         i = 4;
  29.         s = 5.0;
  30.         iflag = 1;
  31.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  32.         printr(a,nrow,ncol);                /* print the result  */
  33.  
  34.  
  35.     /* Second case, switch rows 5 and 2 */
  36.         afil(a,b,ne);           /* fill array for start */
  37.         i = 5;
  38.         j = 2;
  39.         iflag = 2;
  40.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  41.         printr(a,nrow,ncol);                /* print the result  */
  42.  
  43.     /* Third case, multiply row 3 by 4.0 and add the result to row 5 */
  44.         afil(a,b,ne);           /* fill array for start */
  45.         i = 5;
  46.         j = 3;
  47.         s = 4.0;
  48.         iflag = 3;
  49.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  50.         printr(a,nrow,ncol);                /* print the result  */
  51.  
  52.     /* Fourth case, multiply column 4 by the scalar 5.0 */
  53.         afil(a,b,ne);           /* fill array for start */
  54.         i = 4;
  55.         s = 5.0;
  56.         iflag = 4;
  57.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  58.         printr(a,nrow,ncol);                /* print the result  */
  59.  
  60.     /* Fifth case, switch columns 5 and 2 */
  61.         afil(a,b,ne);           /* fill array for start */
  62.         i = 5;
  63.         j = 2;
  64.         iflag = 5;
  65.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  66.         printr(a,nrow,ncol);                /* print the result  */
  67.  
  68.     /* Sixth Case, multiply column 3 by 4.0 and add the result to column 5 */
  69.         afil(a,b,ne);           /* fill array for start */
  70.         i = 5;
  71.         j = 3;
  72.         s = 4.0;
  73.         iflag = 6;
  74.         maelem(lra,nrow,ncol,a,i,j,s,iflag);/* call the function */
  75.         printr(a,nrow,ncol);                /* print the result  */
  76.  
  77.         }
  78.  
  79.                 /* Routine to print matrices */
  80.  
  81.       printr(a,nrow,ncol)
  82.  
  83.         int nrow,ncol;
  84.         float a[];
  85.  
  86.       {
  87.         int *fp,j,k,ne;
  88.  
  89.         ne=ncol-1;
  90.  
  91.         *fp=fopen("PRN:","w");                 /* open the printer */
  92.  
  93.         fprintf(*fp,"Test Results from MAELEM\n\n");
  94.          printf("Test Results from MAELEM\n\n");
  95.  
  96.         for(j = 0; j <= nrow-1 ; j++)
  97.          {
  98.           for(k = j*ncol; k <= j*ncol+ne ; k++)
  99.            {
  100.             fprintf(*fp,"%4.1f  ",a[k]);
  101.              printf("%4.1f  ",a[k]);
  102.            };
  103.            fprintf(*fp,"\n");
  104.             printf("\n");
  105.          }
  106.            fprintf(*fp,"\n\n");
  107.             printf("\n\n");
  108.  
  109.        }
  110.  
  111.   afil(a,b,ne)          /* routine to reset array to original form */
  112.  
  113.         int ne;
  114.         float a[],b[];
  115.  
  116.      {
  117.         int i;
  118.  
  119.         for(i = 0; i <= ne-1; i++)
  120.           a[i] = b[i];
  121.      }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.