NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
02-c-style-heap.cxx
Go to the documentation of this file.
1 
6 #include <cstdio>
7 
8 
9 void initialize(double *x, int n)
10 {
11  for (int i=0;i<n;i++) x[i]= 1.0/(double)(1+n-i);
12 }
13 
14 double sum_elements(double *x, int n)
15 {
16  double sum=0;
17  for (int i=0;i<n;i++) sum+=x[i];
18  return sum;
19 }
20 
21 int main()
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 }
36 
void initialize(double *x, int n)
A::value_type sum(const A &a)
Sum of array or expression.
Definition: util.ixx:81
int main()
double sum_elements(double *x, int n)