NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
01-c-style-stack.cxx File Reference
+ Include dependency graph for 01-c-style-stack.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:
01-c-style-stack.cxx.

Definition at line 14 of file 01-c-style-stack.cxx.

15 {
16  for (int i=0;i<n;i++) x[i]= 1.0/(double)(1+n-i);
17 }
double sum_elements ( double *  x,
int  n 
)
Examples:
01-c-style-stack.cxx.

Definition at line 20 of file 01-c-style-stack.cxx.

21 {
22  double sum=0;
23  for (int i=0;i<n;i++) sum+=x[i];
24  return sum;
25 }
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:
01-c-style-stack.cxx.

Definition at line 27 of file 01-c-style-stack.cxx.

28 {
29  const int n=12345678;
30  // Declare the array and place it on the stack
31  double x[n];
32 
33  initialize(x,n);
34  double s=sum_elements(x,n);
35  printf("sum=%e\n",s);
36 
37  // Before returning, the space on the stack is freed
38  return 0;
39 }
void initialize(double *x, int n)
double sum_elements(double *x, int n)

+ Here is the call graph for this function: