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 @@
void sequence(int n, int max_age) {
int i;
long long mature = 0,
died = 0;
long long *born = malloc((n+1) * sizeof(long long));
printf("size: %d\n", sizeof(long long));
long long mature = 0, died = 0, pop_new, pop_old = 1,
*born = malloc((n + 1) * sizeof(long long)),
*diff = malloc((n + 1) * sizeof(long long));
printf("popu:");
......@@ -19,21 +17,22 @@ void sequence(int n, int max_age) {
died = i < max_age ? 0 : born[i - max_age];
born[i] = mature;
mature = mature + born[i - 1] - died;
printf(" %lld", mature + born[i]);
printf(" %lld", pop_new = mature + born[i]);
diff[i] = pop_new - pop_old;
pop_old = pop_new;
}
born[i] = mature;
puts("");
printf("diff: ");
for( i = 1; i < n; i++ )
printf(" %lld", born[i]);
printf(" %lld", diff[i]);
puts("");
free(born);
free(diff);
}
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