Commit 4a712f13 authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim: added growth output to assisgnment 2.7.

parent 15d8e6cb
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
void sequence(int n, int max_age) { void sequence(int n, int max_age) {
int i; int i;
long long mature = 0, long long mature = 0, died = 0, pop_new, pop_old = 1,
died = 0; *born = malloc((n + 1) * sizeof(long long)),
*diff = malloc((n + 1) * sizeof(long long));
long long *born = malloc((n+1) * sizeof(long long));
printf("size: %d\n", sizeof(long long));
printf("popu:"); printf("popu:");
...@@ -19,21 +17,22 @@ void sequence(int n, int max_age) { ...@@ -19,21 +17,22 @@ void sequence(int n, int max_age) {
died = i < max_age ? 0 : born[i - max_age]; died = i < max_age ? 0 : born[i - max_age];
born[i] = mature; born[i] = mature;
mature = mature + born[i - 1] - died; mature = mature + born[i - 1] - died;
printf(" %lld", pop_new = mature + born[i]);
printf(" %lld", mature + born[i]); diff[i] = pop_new - pop_old;
pop_old = pop_new;
} }
born[i] = mature;
puts(""); puts("");
printf("diff: "); printf("diff: ");
for( i = 1; i < n; i++ ) for( i = 1; i < n; i++ )
printf(" %lld", born[i]); printf(" %lld", diff[i]);
puts(""); puts("");
free(born); free(born);
free(diff);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment