Changeset 6e7e2b36 for src/examples


Ignore:
Timestamp:
Jun 1, 2015, 8:52:19 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

redo automake seventh attempt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/sum.c

    rd1d17f5 r6e7e2b36  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:43:46 2015
    13 // Update Count     : 4
     12// Last Modified On : Mon Jun  1 20:46:35 2015
     13// Update Count     : 18
    1414//
    1515
     
    4242
    4343int main() {
    44         const int size = 10, low = 0, High = 10;
    45         int si = 0, ai[10]; // size
    46         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;
    5050        }
    5151        printf( "sum from %d to %d is %d, check %d\n",
    5252                        low, High, sum( size, ai ), si );
    5353
    54 //      char ci[10];
     54//      char ci[size];
    5555//      char c = sum( size, ci );
    56 //      float fi[10];
     56//      float fi[size];
    5757//      float f = sum( size, fi );
    5858
    59         double sd = 0.0, ad[10];                                                        // size
    60         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;
    6464        }
    6565        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 );
    6767}
    6868
Note: See TracChangeset for help on using the changeset viewer.