Question: Has to be on C Run-able, Correct Syntax source code errors there are no real logic errors Follow Requirements and Comments in the Code Put

Has to be on C

  1. Run-able,
  2. Correct Syntax source code errors there are no real logic errors
  3. Follow Requirements and Comments in the Code
    1. Put your answer where the comment //what R we doing?
  4. You do not need to follow Standards, but you name must be in the header comment
  5. In the code place comments before each for-loop explaining what the loop results are achieving.
  6. Answer the following questions and place the answer is in your header comment.
  7. Your file name will be Hw5.c.

Questions:

  1. Run the code in debug mode: Notice the code is spinning in the second loop.
    1. WHY is i greater than the limit, answer this and you understand the infinite loop you are executing.
    2. Fix the infinite loop
  2. Once you get all three loops working.
    1. Set breakpoints
      1. At each loop
      2. On the line //Just a place holder to Breakpoint
    2. By Watching the symbol sieveArray expand array +, and move any symbols above the symbol sieveArray.
    3. Describe the function of each loop as it pertains to find PRIME numbers and MULTIPLES

Congratulations, you know a little bit more about identifiers, symbolics, simple debugging techniques and algorithm analysis, through the process of reverse engineering.

Appendix A

This code finds all prime numbers within a specific range (0-127) without and mathematical algorithms or functions.

// This is the header Comment Field

// Function of the code: Sieve of Eratosthenes

// Non-Math solution

#define LIMIT 127; // symbolic constant to define the size of the array

main()

{

// DO NOT alter the size of the following Identifiers

// in your solution - 5 points off if you do

char sieveArray[LIMIT], i,j; // These VARs must retain same data size of this

// first loop

for ( i=0; i <= LIMIT; i++)

sieveArray[i]=-1; //what R we doing?

// second loop iteration

for( i=4; i <= LIMIT; i+=2 )

{

sieveArray[i] = 2; //what R we doing?

}

// third loop nested loop

for( i=3; i <= LIMIT; i += 2 )

{

j=i+i;

while ( j <= LIMIT)

{

sieveArray[j+=i] = i; //what R we doing?

}

}

}//main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!