diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
| commit | 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch) | |
| tree | ed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/compiler/p5-compiler/data/test14.c | |
| download | misc-undergrad-main.tar.gz misc-undergrad-main.zip | |
Diffstat (limited to 'Homework/cs5300/compiler/p5-compiler/data/test14.c')
| -rw-r--r-- | Homework/cs5300/compiler/p5-compiler/data/test14.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Homework/cs5300/compiler/p5-compiler/data/test14.c b/Homework/cs5300/compiler/p5-compiler/data/test14.c new file mode 100644 index 0000000..45565fa --- /dev/null +++ b/Homework/cs5300/compiler/p5-compiler/data/test14.c @@ -0,0 +1,27 @@ +// Sum the first n elements of the array +int sum(int x[], int n) { + int i; + int sum; + i = 0; + sum = 0; + while (i < n) { + sum = sum + x[i]; + i = i + 1; + } + return sum; +} + +void main() { + int a[10]; + int i; + + println("This should print 6 and 28"); + i = 0; + while (i < 10) { + a[i] = i; + i = i + 1; + } + + println(sum(a, 4)); + println(sum(a, 8)); +} |
