Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add eratosthenes sieve method for finding primes below given number#672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
anoopemacs wants to merge7 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromanoopemacs:master

Conversation

@anoopemacs
Copy link

@anoopemacsanoopemacs commentedOct 17, 2020
edited by gitpod-iobot
Loading

Description of Change

Notes: Added 'Sieve of Eratosthenes' algorithm along with test cases for primes below 100

@Panquesito7Panquesito7 added the enhancementNew feature or request labelOct 18, 2020
Copy link
Member

@Panquesito7Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well written and documented code. 😄 👍
Please enableGitHub Actions in your repository of this fork in this link:https://github.com/anoopemacs/C/actions

* Test function
* @return void
*/
void test()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
voidtest()
staticvoidtest()

}

/**
* Test function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
*Testfunction
*@briefTestfunction

}

/**
* Driver Code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
*DriverCode
*@briefDriverCode


/**
* Driver Code
* @return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
* @returnNone
* @returns0onexit

@@ -0,0 +1,72 @@
/**
* @file
* @brief Get list of prime numbers using Sieve of Eratosthenes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Provide a Wikipedia link in Markdown format (if possible).
If there's no Wikipedia link, provide another web source for algorithm explanation. 🙂

Comment on lines 14 to 18
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Provide a brief description of the headers (what do they add).

Suggested change
#include<assert.h>
#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>/// for assert
#include<stdbool.h>///
#include<stdio.h>///
#include<stdlib.h>///
#include<string.h>///

Copy link
Member

@Panquesito7Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Amazing work, I like how you've made the code. 😄 👍
Code and documentation is pretty good and refined; LGTM. 🙂

@Panquesito7Panquesito7 added approvedApproved; waiting for merge and removed Changes requested labelsOct 18, 2020
@anoopemacs
Copy link
Author

Thank you very much@Panquesito7 for your detailed review and guidance! I really appreciate you taking the time to guide in such detail :)

Panquesito7 reacted with thumbs up emojiPanquesito7 reacted with hooray emoji

Copy link
Collaborator

@kvedalakvedala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 well written code. Please check the comments.

*/
bool* sieve(int N)
{
bool* primep = calloc(N+1, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

dynamically allocated memorymust be freeed.
In this case, a note should be added to the function that the functionfree() must be called on the output pointer after its use.

For example, on line# 48, pointer to a new memory is returned. Hence, before the end of that function, there must be afree(primep);

for (size_t i = 0, size = sizeof(primers) / sizeof(primers[0]); i < size;
++i)
{
assert(primep[primers[i]]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the correct loop check would be:

for (size_tj=0,p=0;j<100;j++) {if (j==primers[p])// j is a known prime number  {assert(prime[j]);p++;// this variable is used to keep a track of the index of known prime numbers array  }else {// j is a known composite numberassert(!prime[j]);  }}

This will check that your function ensures that both primes and composites are classified correctly.

assert(primep[primers[i]]);
}

/* Example Non-prime numbers */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

good code :)
but becomes redundant after the above suggested loop. You can keep this loop as well - I like it as it is a good exercise

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kvedalakvedalakvedala left review comments

@Panquesito7Panquesito7Panquesito7 approved these changes

Assignees

No one assigned

Labels

approvedApproved; waiting for mergeenhancementNew feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@anoopemacs@kvedala@Panquesito7

[8]ページ先頭

©2009-2025 Movatter.jp