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

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

last proofread array chapter

  • Property mode set to 100644
File size: 600 bytes
Line 
1#include <stddef.h>
2#include <stdio.h>
3
4
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 size_t n, float x[] ) {
23 double sum = 0;
24 for ( size_t i = 0;
25 i < BND( n ); i++ )
26 sum += @x[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 float x[EXPSZ];
45 for ( size_t i = 0; i < EXPSZ; i++ ) x[i] = 0.1 * (i + 1);
46 for ( size_t i = 0; i < EXPSZ; i++ ) printf("elm %zd %g\n", i, x[i]);
47 double sum_ret = sum( EXPSZ, x );
48 printf( "sum %2g\n", sum_ret );
49}
50
51
52
53#endif
Note: See TracBrowser for help on using the repository browser.