Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I really have hard time understanding these functions. Can anyone with good know

ID: 3620546 • Letter: I

Question

I really have hard time understanding these functions.

Can anyone with good knowledge explain line by line what it is doing ? (Assuming the size can be any number between 2 and 10000)

void runsieve(int size)
{
/* replace 1 with 0 at each index which is not a prime */
int top=(int)sqrt(size);
int i,k;

/* remove all multiples of i, i=2....top */
for(i=2; i<=top; i++)
if(sieve[i]) /* new only for prime i */
    for(k=2*i; k<=size; k+=i)
      sieve[k]=0;

}

void printsieve(int size)
{
int i;
for(i=2; i<=size; i++)
if(sieve[i]) /* if i is marked prime */
    printf("%5d", i);
}

Explanation / Answer

void runsieve(int size) { /* initializing the variable top with the square of the entered size, if the size is 2, then top will be 4 */ int top=(int)sqrt(size); /*defining i(the loop counter), and k (the inner loop counter)*/ int i,k; /* start looping from index 2 (since it's the minimum)to index top (or 4 in our case) */ for(i=2; i