Question

Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the console (inclusive). The identified prime numbers must be stored in an array . The inputted number should be between 0 and 1000 (inclusive). array is large enough to o Make sure your hold all the prim e numbers. Dynamic memory allocation is not required for this assignment, so you can have unused space in your array Make sure you can handle the cases of the user inputting 0,1, or a number outside the valid range. o You dont have to use an efficient algorithm to find the prime numbers. You can just use brute force to divide each test number by all of the smaller numbers (starting at 2). If a number is evenly divisible by any number other than 1 and itself, then that number is not * prime. Youll know if a number is evenly divisible by another number if the remainder of the division is 0-Remember that the modulus (%) operator can be used to find the remainder in C/C++ o Next, you will perform a series of multiplications on pairs of opposite prime numbers: First, you will multiply the 1s (smallest) prime number by the last (largest) prime number in your prime number array. The result must be stored as the first element of another array Then, vou will multiply the second prime number by the next-to-last (n-1) prime number and store the result as the second element of the other array After that, you will multiply the third and (n-2) prime numbers and store the result as the third element of the other aay Repeat this process umtil every pair of opposite prime mumbers has been multiplied and stored. Figure 1 and Figure 2 below demonstrate the process for an array with an even number of prime numbers. Ifthe number of prime numbers is odd, then you will ignore the middle element. Figure 3 and Figure 4 demonstrate the odd process. Prime number array for input 20 13 17 15 Product of extreme elements: 38 51 65 Total 4 Figure 1: Multiplications for an even mmber of prime mumbersMicrosoft Visual Studio Debug Console nter a nusber between 1e08: 2e otal nusber of prise nusabers found:8 Total number of elements in the #ultiplication output array: 4 Figure 2: Output for an even number of prime numbers gnore Prime number array for input 25 ii 13 17 19 23 Product of extreme elements4 57 85 91 Total 4 Figure 3: Maltiplications for an odd number of prime mmbers. Microsoft Visual Studio Debug Console nter a nusber between 1e0: 25 Total nusber of prise nusbers found:9 Total number of elesents in the sultiplication output array: 4 Figure 4: Output for an odd number of prime numbers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>

using namespace std;

bool isPrime(int num){

for(int i=2;i<num;i++){

if(num%i == 0)

return false;

}

return true;

}

int main(){

int n;

int arr[1004],mularr[1004];

int count = 0,mulCount=0;

cout << "Enter a number between 0-1000: ";

cin >> n;

while(n>1000 && n<0){

cout << "Enter a number between 0-1000: ";

cin >> n;

}

cout << endl;

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

if(isPrime(i)){

arr[count] = i;

count++;

}

}

cout << "Total number of prime numbers found: " << count << endl;

for(int i=0;i<count;i++)

cout << arr[i] << endl;

cout << endl;

for(int i=0;i<count/2;i++){

mularr[mulCount] = arr[i]*arr[count-i-1];

mulCount++;

}

cout << "Total number of elements in the multiplication output array: " << mulCount<<endl;

for(int i=0;i<mulCount;i++)

cout << mularr[i] << endl;

}

Add a comment
Know the answer?
Add Answer to:
Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT