diff options
author | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2023-04-10 09:17:11 -0600 |
---|---|---|
committer | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2023-04-10 09:17:11 -0600 |
commit | 5f28f80c4e25a56cd444914c2f0b3da5e7fdb088 (patch) | |
tree | 600ad8b1ec5aad5155baf8c0352281054a8e6366 /data/test14.c | |
download | cminus-5f28f80c4e25a56cd444914c2f0b3da5e7fdb088.tar.gz cminus-5f28f80c4e25a56cd444914c2f0b3da5e7fdb088.zip |
Initial commit - building
Diffstat (limited to 'data/test14.c')
-rw-r--r-- | data/test14.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/data/test14.c b/data/test14.c new file mode 100644 index 0000000..45565fa --- /dev/null +++ b/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)); +} |