In COMP2521, you are allowed to use small amounts (< 10 lines) of general purpose code (not related to the assessment) obtained from external websites such as Stack Overflow. You are also allowed to use any amount of code from the current iteration of the course. If you do so, you must clearly attribute the source of this code in an accompanying comment. This comment must:
Example:
// Gets a list of all prime numbers up to 'n' List getPrimes(int n) { List res = ListNew(); bool *prime = malloc((n + 1) * sizeof(bool)); assert(prime != NULL); memset(prime, true, n + 1); // The following code was taken from https://www.geeksforgeeks.org/sieve-of-eratosthenes/ // It uses the Sieve of Eratosthenes to generate prime numbers for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { ListAppend(res, p); for (int i = p * p; i <= n; i += p) { prime[i] = false; } } } free(prime); return res; }
Resource created Monday 05 September 2022, 11:21:09 AM.