RWalib C Array Library User Guide > Arithmetic Operations > alibSum
  

alibSum
Sums the elements in an array. The PV-WAVE API for this routine is the TOTAL Function.
Prototypes
wvlong alibSumb( wvlong n, UCHAR *b )
wvlong alibSums( wvlong n, short *b )
wvlong alibSumi( wvlong n, int *b )
wvlong alibSuml( wvlong n, wvlong *b )
double alibSumf( wvlong n, float *b )
double alibSumd( wvlong n, double *b )
COMPLEX alibSumc( wvlong n, COMPLEX *b )
DCOMPLEX alibSumz( wvlong n, DCOMPLEX *b )
Parameters
n — (Input) The number of elements in the source array.
*b — (Input) The n-element source array.
Return value
The sum of the elements in array b. Computation is done in the data-type of the return value.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
    /* make up some data for the example */
        UCHAR  b0[9]={0,1,2,3,4,5,6,7,8};
        wvlong b;
    printf( "\n\n show 9-element vector b0" );
        alibinit( NULL, NULL, NULL, NULL );
        alibPrintArrayb( 1, 1, 1, 9, b0, NULL );
    printf( "\n\n print the sum of the elements in b0" );
        b = alibSumb( 9, b0 );
        alibPrintArrayl( 1, 1, 1, 1, &b, NULL );
}
 
Output:
 
 show 9-element vector b0
 
   0   1   2   3   4   5   6   7   8
 
 print the sum of the elements in b0
 
                   36

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.