Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students explore these related Databases questions

Question

5. Who should facilitate the focus group?

Answered: 3 weeks ago