Homework Solution: Please write a C++ programming code following those instructions​…

Please write a C++ programming code following those instructions​
A prime number is a number greater than 1 that has no positive integer divisors other than 1 and itself. Conversely, a composite number is any number greater than 1 that is divisible by numbers other than 1 and itself. In other words, a composite number is any number greater than 1 that is not a prime number. To help elucidate the distinction between these two types of numbers, you will write a program that accepts as input a positive integer n and outputs a list of all the prime numbers in the range [2, n] followed by a list of all the composite numbers lying in the same range. To ensure that your program always terminates within a reasonable amount of time, you will separate the prime and composite numbers using the Sieve of Eratosthenes The Sieve of Eratosthenes is an algorithm designed to efficiently find all prime numbers less than a given integer limit n. The algorithm indirectly identifies prime numbers by iteratively marking as composite the multiples of each prime found starting from the first prime number 2. The steps of the algorithm are enumerated as follows 1. Create an ordered list l of all integers in the range 2,n] 2. Initialize the first prime number p 2 3. Starting from index 2 * p, iterate over the ordered list l in increments of p and lace a mark on each number visited 4. Find the first unmarked number larger than p in the ordered list I. If no such number is found, exit the algorithm, otherwise, set p to the unmarked value. 5. If p > LVn], exit the algorithm, otherwise, return to step 3 An illustrative example of the Sieve of Eratosthenes is provided as follows に[2, 3, 4, 5, 6, 7, 8, 9, 10] » 1st Iteration: p = 2 (First prime number) Iterate and mark in increments of 2 [2,3,A, 5,6,7,8,9,10] » 2nd Iteration: p = 3 (Next unmarked number larger than 2) Iterate and mark in increments of 3 2,3,A,5,6, 7,8,9,X 3rd Iteration 5 > |V10| so exit algorithm

please refer below code # include<iostream> # include<cstdlib>

Please transcribe a C++ programming statute aftercited those instructions​

A perfect enumerate is a enumerate main than 1 that has no explicit integer divisors other than 1 and itself. Conversely, a composite enumerate is any enumerate main than 1 that is discerptible by enumerates other than 1 and itself. In other expression, a composite enumerate is any enumerate main than 1 that is integraludeable attributable attributable attributable a perfect enumerate. To aid explain the difference betwixt these span types of enumerates, you earn transcribe a program that accepts as input a explicit integer n and outputs a roll of full the perfect enumerates in the order [2, n] followed by a roll of full the composite enumerates mendacious in the identical order. To determine that your program regularly terminates amid a cool total of date, you earn disconnected the perfect and composite enumerates using the Sieve of Eratosthenes The Sieve of Eratosthenes is an algorithm adapted to efficiently confront full perfect enumerates hither than a dedicated integer stipulation n. The algorithm by-and-by identifies perfect enumerates by iteratively symptoming as composite the multiples of each perfect plant starting from the principal perfect enumerate 2. The plods of the algorithm are enumerated as follows 1. Create an ordered roll l of full integers in the order 2,n] 2. Initialize the principal perfect enumerate p 2 3. Starting from renunciation 2 * p, cite balance the ordered roll l in increments of p and lace a symptom on each enumerate visited 4. Confront the principal unmarked enumerate larger than p in the ordered roll I. If no such enumerate is plant, egress the algorithm, differently, established p to the unmarked esteem. 5. If p > LVn], egress the algorithm, differently, come-back to plod 3 An customary in of the Sieve of Eratosthenes is granted as follows に[2, 3, 4, 5, 6, 7, 8, 9, 10] » 1st Iteration: p = 2 (Principal perfect enumerate) Cite and symptom in increments of 2 [2,3,A, 5,6,7,8,9,10] » 2nd Iteration: p = 3 (Next unmarked enumerate larger than 2) Cite and symptom in increments of 3 2,3,A,5,6, 7,8,9,X 3rd Iteration 5 > |V10| so egress algorithm

Expert Response

# include<iostream>

# include<cstdlib>

using namespace std;

typedef struct enumerate

{

unsigned int N;

bool visited;

}number;

int main(int argc, char *argv[])

{

unsigned int n;

enumerate *arr;

if(argc != 2)

{

cout<<“Missing Argument”<<endl;

come-back 0;

}

else

{

n = atoi(argv[1]);

arr = newlightlight enumerate[n+1]; //creating deck of constituency of dimension n+1

//setting full enumerates with identical enumerate and fabricate visited as false

for(unsigned int i = 0; i <= n; i++)

{

arr[i].N = i;

arr[i].visited = false;

}

//running loop from 2 to sqrt(n)

for(unsigned int i = 2; i * i <= n; i++)

{

//If enumerates is integraludeable attributable attributable attributable visited

if(!arr[i].visited)

{

for(unsigned int j = i * 2; j <= n; j += i) //marking full the multiples as visited

arr[j].visited = true;

}

}

//printing perfect and composite enumerates

for(unsigned int i = 2; i <= n; i++)

{

if(!arr[i].visited)

cout<<arr[i].N<<“t”;

}

cout<<endl;

for(unsigned int i = 2; i <= n; i++)

{

if(arr[i].visited)

cout<<arr[i].N<<“t”;

}

cout<<endl;

}

come-back 0;

}

please integralude beneath snapshot control integraludeence