Tag: 悬垂指针

C中Eratosthenes算法的筛选

好的,所以我创建的这个函数使用Sieve of Eratosthenes算法来计算所有素数<= n。 此函数存储参数中的素数和素数计数。 当函数退出时,素数应指向一个动态分配的内存块,其中包含所有素数<= num。 *count将具有素数。 这是我的函数getPrimes : void getPrimes(int num, int* count, int** array){ (*count) = (num – 1); int sieve[num-1], primenums = 0, index, fillnum, multiple; //Fills the array with the numbers up to the user’s ending number, num. for(index = 0, fillnum = 2; fillnum <= num; index++, fillnum++){ sieve[index] […]