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

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

ID: 3751761 • Letter: I

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 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 <iostream.h>

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;

}

Explanation / Answer

/*If you have any query do comment in the comment section else like the solution*/

6. Making array dynamic

#include <iostream>
using namespace std;
int main()
{
int N;
cout<<"Enter value of N : "; //Change that needs to be done to make the array dynamic
cin>>N;
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;

}

7. By using vector

#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
cout<<"Enter value of N : "; //Change that needs to be done to make the array dynamic
cin>>N;
int i;
vector<int> 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;

}