Changeset 6e7e2b36 for src/examples
- Timestamp:
- Jun 1, 2015, 8:52:19 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- c3a4385
- Parents:
- d1d17f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/sum.c
rd1d17f5 r6e7e2b36 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:43:46201513 // Update Count : 412 // Last Modified On : Mon Jun 1 20:46:35 2015 13 // Update Count : 18 14 14 // 15 15 … … 42 42 43 43 int main() { 44 const int size = 10, low = 0, High = 10;45 int si = 0, ai[ 10]; // size46 int i;47 for ( i = low; i < High; i+= 1 ) {48 si += i;49 ai[i] = i;44 const int low = 5, High = 15, size = High - low; 45 int si = 0, ai[size]; 46 int v = low; 47 for ( int i = 0; i < size; i += 1, v += 1 ) { 48 si += v; 49 ai[i] = v; 50 50 } 51 51 printf( "sum from %d to %d is %d, check %d\n", 52 52 low, High, sum( size, ai ), si ); 53 53 54 // char ci[ 10];54 // char ci[size]; 55 55 // char c = sum( size, ci ); 56 // float fi[ 10];56 // float fi[size]; 57 57 // float f = sum( size, fi ); 58 58 59 double sd = 0.0, ad[ 10]; // size60 for ( i = low; i < High; i += 1 ) {61 double d = i / (double)size;62 sd += d;63 ad[i] = d;59 double sd = 0.0, ad[size]; 60 double v = low / 10.0; 61 for ( int i = 0; i < size; i += 1, v += 0.1 ) { 62 sd += v; 63 ad[i] = v; 64 64 } 65 65 printf( "sum from %g to %g is %g, check %g\n", 66 low / (double)size, High / (double)size, sum( size, ad ), sd );66 low / 10.0, High / 10.0, sum( size, ad ), sd ); 67 67 } 68 68
Note: See TracChangeset
for help on using the changeset viewer.