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
- Run-able,
- Correct Syntax source code errors there are no real logic errors
- Follow Requirements and Comments in the Code
- Put your answer where the comment //what R we doing?
- You do not need to follow Standards, but you name must be in the header comment
- In the code place comments before each for-loop explaining what the loop results are achieving.
- Answer the following questions and place the answer is in your header comment.
- Your file name will be Hw5.c.
Questions:
- Run the code in debug mode: Notice the code is spinning in the second loop.
- WHY is i greater than the limit, answer this and you understand the infinite loop you are executing.
- Fix the infinite loop
- Once you get all three loops working.
- Set breakpoints
- At each loop
- On the line //Just a place holder to Breakpoint
- By Watching the symbol sieveArray
expand array +, and move any symbols above the symbol sieveArray. - Describe the function of each loop as it pertains to find PRIME numbers and MULTIPLES
- Set breakpoints
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
Get step-by-step solutions from verified subject matter experts
