source: doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cc

Last change on this file was 80e83b6c, checked in by Peter A. Buhr <pabuhr@…>, 6 days ago

last proofread array chapter

  • Property mode set to 100644
File size: 666 bytes
Line 
1#include <cstddef>
2#include <iostream>
3#include <vector>
4using namespace std;
5
6#ifdef UNSOUND_BOUND
7 #define BND( correct_limit ) 100
8#else
9 #define BND( correct_limit ) correct_limit
10#endif
11
12
13
14
15
16
17
18
19
20
21double sum(
22 vector<float> & x ) {
23 double sum = 0;
24 for ( size_t i = 0;
25 i < BND( x.size() ); i++ )
26 sum += @x.at(i)@;
27 return sum;
28}
29
30
31
32
33
34
35#ifdef RUNIT
36
37#define EXPSZ 7
38
39
40
41
42
43int main() {
44 vector<float> x( EXPSZ );
45 for ( size_t i = 0; i < EXPSZ; i++ ) x.at(i) = 0.1 * (i + 1);
46 for ( size_t i = 0; i < EXPSZ; i++ ) cout << "elm " << i << " " << x[i] << endl;
47 double sum_ret = sum( x );
48 cout << "sum " << sum_ret << endl;
49}
50
51
52
53#endif
Note: See TracBrowser for help on using the repository browser.