2022-01-13 21:45:54 +00:00
|
|
|
// sum.c
|
2022-01-12 09:04:41 +00:00
|
|
|
// David_Harris@hmc.edu 24 December 2021
|
|
|
|
// Simple illustration of compiling C code
|
|
|
|
|
|
|
|
#include <stdio.h> // supports printf
|
|
|
|
#include "util.h" // supports verify
|
|
|
|
|
|
|
|
long sum(long N) {
|
|
|
|
long result, i;
|
|
|
|
result = 0;
|
|
|
|
for (i=1; i<=N; i++) {
|
|
|
|
result = result + i;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
int s[1], expected[1];
|
2022-01-13 21:45:54 +00:00
|
|
|
setStats(1);
|
2022-01-12 09:04:41 +00:00
|
|
|
s[0] = sum(4);
|
2022-01-13 21:45:54 +00:00
|
|
|
setStats(0);
|
2022-01-12 09:04:41 +00:00
|
|
|
printf("s = %d\n", s[0]);
|
|
|
|
expected[0] = 10;
|
|
|
|
return verify(1, s, expected); // 0 means success
|
|
|
|
}
|