Question: IN C++ WILL UPVOTE CORRECT SOLUTION ASAP - ONLY NEED PARTS 6 AND 7! 1. Make the following code work in your environment. 2. Modify

IN C++ WILL UPVOTE CORRECT SOLUTION ASAP - ONLY NEED PARTS 6 AND 7!

1. Make the following code work in your environment.

2. Modify it so that you can time first two for loops in the code seperately from timing the third for loop in the code. This may require increasing the value of N to get a positive result.

3. Modify the display of the results so that each line only contains 10 numbers

4. Change the array type from int to char and comment on changes to run time.

5. Change the array type to bool and comment on changes to run time.

6. Change the static array in part A to a dynamic array and compare the run times

to the variations you tried in parts 1-5. Be sure to use types char and bool in your testing.

7. Change the static array in part A to a vector and compare the run times

to the variations you tried in parts 1-5. Be sure to use types char and bool in your testing.

#include

static const int N = 1000;

int main()

{ int i, a[N];

for (i = 2; i < N; i++) a[i] = 1;

for (i = 2; i < N; i++)

if (a[i])

for (int j = i; j*i < N; j++) a[i*j] = 0;

for (i = 2; i < N; i++)

if (a[i]) cout << " " << i;

cout << endl;

}

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!