NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
02-c-style-heap.cxx File Reference
+ Include dependency graph for 02-c-style-heap.cxx:

Go to the source code of this file.

Functions

void initialize (double *x, int n)
 
double sum_elements (double *x, int n)
 
int main ()
 

Function Documentation

void initialize ( double *  x,
int  n 
)
Examples:
02-c-style-heap.cxx.

Definition at line 9 of file 02-c-style-heap.cxx.

10 {
11  for (int i=0;i<n;i++) x[i]= 1.0/(double)(1+n-i);
12 }
double sum_elements ( double *  x,
int  n 
)
Examples:
02-c-style-heap.cxx.

Definition at line 14 of file 02-c-style-heap.cxx.

15 {
16  double sum=0;
17  for (int i=0;i<n;i++) sum+=x[i];
18  return sum;
19 }
A::value_type sum(const A &a)
Sum of array or expression.
Definition: util.ixx:81

+ Here is the call graph for this function:

int main ( void  )
Examples:
02-c-style-heap.cxx.

Definition at line 21 of file 02-c-style-heap.cxx.

22 {
23  const int n=12345678;
24 
25  // Allocate an array on the heap
26  double* x=new double[n];
27 
28  initialize(x,n);
29  double s=sum_elements(x,n);
30  printf("sum=%e\n",s);
31 
32  // Free the space previously allocated.
33  delete[] x;
34  return 0;
35 }
void initialize(double *x, int n)
double sum_elements(double *x, int n)

+ Here is the call graph for this function: