cs_cumsum.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
00003 double cs_cumsum (int *p, int *c, int n)
00004 {
00005     int i, nz = 0 ;
00006     double nz2 = 0 ;
00007     if (!p || !c) return (-1) ;     /* check inputs */
00008     for (i = 0 ; i < n ; i++)
00009     {
00010         p [i] = nz ;
00011         nz += c [i] ;
00012         nz2 += c [i] ;              /* also in double to avoid int overflow */
00013         c [i] = p [i] ;             /* also copy p[0..n-1] back into c[0..n-1]*/
00014     }
00015     p [n] = nz ;
00016     return (nz2) ;                  /* return sum (c [0..n-1]) */
00017 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


hogman_minimal
Author(s): Maintained by Juergen Sturm
autogenerated on Wed Dec 26 2012 15:36:47