Debian Codegraph @

benchmarks.larceny/src/sum.c

raw
1 /* SUM -- Compute sum of integers from 0 to 10000 */
2
3 #include <stdio.h>
4
5 static int run (int n)
6 {
7 int i = n, sum = 0;
8
9 while (i >= 0)
10 {
11 sum = sum+i;
12 i = i-1;
13 }
14
15 return sum;
16 }
17
18 int main (int argc, char *argv[])
19 {
20 int i;
21 int result;
22 int n = 10000;
23
24 if (argc > 1)
25 n = atoi (argv[1]);
26
27 for (i=0; i<20000; i++)
28 result = run (n);
29
30 if (result != 50005000)
31 printf ("*** wrong result ***\n");
32
33 return 0;
34 }