feat: update structure
This commit is contained in:
21
cs2106/labs/lab1/part2/lab1p2b.c
Normal file
21
cs2106/labs/lab1/part2/lab1p2b.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int accumulate(int x) {
|
||||
// Modify this function so that it accumulates values passed to it to
|
||||
// a value called "acc".
|
||||
|
||||
static int acc = 0;
|
||||
|
||||
acc = acc + x;
|
||||
printf("acc is now %d\n", acc);
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
// Call fun2 to accumulate from 1 to 10
|
||||
for(int i=1; i<=10; i++)
|
||||
accumulate(i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user