NUMCXX
0.13.20181108
Numerical library for small projects and teaching purposes
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
examples
00-cxx-basics
01-c-style-stack.cxx
Go to the documentation of this file.
1
7
#include <cstdio>
8
9
// Initialize the vector with some data
10
//
11
// Functions using plain c style arrays need to have
12
// both the pointer to the data and the size information
13
// as parameters.
14
void
initialize
(
double
*x,
int
n)
15
{
16
for
(
int
i=0;i<n;i++) x[i]= 1.0/(
double
)(1+n-i);
17
}
18
19
// Sum up the elements of the vector and return the value
20
double
sum_elements
(
double
*x,
int
n)
21
{
22
double
sum
=0;
23
for
(
int
i=0;i<n;i++) sum+=x[i];
24
return
sum
;
25
}
26
27
int
main
()
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
}
main
int main()
Definition:
01-c-style-stack.cxx:27
numcxx::sum
A::value_type sum(const A &a)
Sum of array or expression.
Definition:
util.ixx:81
initialize
void initialize(double *x, int n)
Definition:
01-c-style-stack.cxx:14
sum_elements
double sum_elements(double *x, int n)
Definition:
01-c-style-stack.cxx:20
Generated on Thu Nov 8 2018 22:52:26 for NUMCXX by
1.8.11