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
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started