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

  1.         /* General form test program for scientific functions */
  2.  
  3.         /* Routine Tested:  MARITH */
  4.  
  5.         main()
  6.  
  7.         {
  8.         int iflag,lra,lrb,lrc,nrow,ncol;
  9.         static float a[5][6]={0.,-1.,-2.,-3.,-4.,-5.,
  10.                               1., 0.,-1.,-2.,-3.,-4.,
  11.                               2., 1., 0.,-1.,-2.,-3.,
  12.                               3., 2., 1., 0.,-1.,-2.,
  13.                               4., 3., 2., 1., 0.,-1.
  14.                              };
  15.         static float b[5][6]={ 0.,-1.,-2.,-3.,-4.,-5.,
  16.                                1., 0.,-1.,-2.,-3.,-4.,
  17.                                2., 1., 0.,-1.,-2.,-3.,
  18.                                3., 2., 1., 0.,-1.,-2.,
  19.                                4., 3., 2., 1., 0.,-1.
  20.                              };
  21.         float c[5][6],scalar;
  22.  
  23.         lra = 6;
  24.         lrb = 6;
  25.         lrc = 6;
  26.         nrow = 5;
  27.         ncol = 6;
  28.         scalar = .5;
  29.  
  30.         /* case 1, add a to b */
  31.         iflag = 1;
  32.         marith(lra,lrb,lrc,nrow,ncol,iflag,a,b,c,scalar);
  33.         printr(c,nrow,ncol);                /* print the result  */
  34.  
  35.         /* case 2, subtract b from a */
  36.         iflag = 2;
  37.         marith(lra,lrb,lrc,nrow,ncol,iflag,a,b,c,scalar);
  38.         printr(c,nrow,ncol);                /* print the result  */
  39.  
  40.         /* case 3, multiply b by scalar */
  41.         iflag = 3;
  42.         marith(lra,lrb,lrc,nrow,ncol,iflag,a,b,c,scalar);
  43.         printr(c,nrow,ncol);                /* print the result  */
  44.  
  45.         /* case 4, multiply b by scalar and add to a */
  46.         iflag = 4;
  47.         marith(lra,lrb,lrc,nrow,ncol,iflag,a,b,c,scalar);
  48.         printr(c,nrow,ncol);                /* print the result  */
  49.  
  50.         /* case 5, multiply b by scalar and subtract from a */
  51.         iflag = 5;
  52.         marith(lra,lrb,lrc,nrow,ncol,iflag,a,b,c,scalar);
  53.         printr(c,nrow,ncol);                /* print the result  */
  54.         }
  55.  
  56.                 /* Routine to print matrices */
  57.  
  58.       printr(a,nrow,ncol)
  59.  
  60.         int nrow,ncol;
  61.         float a[];
  62.  
  63.       {
  64.         int *fp,j,k,ne;
  65.  
  66.         ne = ncol-1;
  67.  
  68.         *fp=fopen("PRN:","w");                 /* open the printer */
  69.  
  70.         fprintf(*fp,"Test Results from MARITH\n\n");
  71.          printf("Test Results from MARITH\n\n");
  72.  
  73.         for(j = 0; j <= nrow-1 ; j++)
  74.          {
  75.           for(k = j*ncol; k <= j*ncol+ne ; k++)
  76.            {
  77.             fprintf(*fp,"%5.1f  ",a[k]);
  78.              printf("%5.1f  ",a[k]);
  79.            };
  80.            fprintf(*fp,"\n");
  81.             printf("\n");
  82.          }
  83.            fprintf(*fp,"\n\n");
  84.             printf("\n\n");
  85.  
  86.        }
  87.  
  88.   afil(a,b,ne)          /* routine to reset array to original form */
  89.  
  90.         int ne;
  91.         float a[],b[];
  92.  
  93.      {
  94.         int i;
  95.  
  96.         for(i = 0; i <= ne-1; i++)
  97.           a[i] = b[i];
  98.      }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.