Question: In C++; Rewrite the exercise that found a predetermined number of primes, putting the number_of_primes_found and last_number_tested variables in a structure. Your main program should

In C++;

Rewrite the exercise that found a predetermined number of primes, putting the number_of_primes_found and last_number_tested variables in a structure. Your main program should now look like:

struct primesequence sequence; while (sequence.number_of_primes_found 
 int number = nextprime(sequence); 
 cout << "Number " << number << " is prime" << endl; } 

And here is my previous code without Structure:

#include

using namespace std;

bool prime_test_function(int n) {

for (int f = 2; f <= n / 2; f++) {

if (n % f == 0) {

return false;

}

}

return true;

}

int main()

{

bool isprime;

int n;

int number_of_primes_found = 0;

cout<<"Enter how many number you want to print: ";

cin >> n;

for(int i=2; number_of_primes_found < n ;i++) {

isprime = prime_test_function(i);

if(isprime) {

number_of_primes_found++;

cout<

}

}

cout<

return 0;

}

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!