Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this in C++, I will give a positive review on it, thank you. Program Requirements First, find all the prime numbers

I need help with this in C++, I will give a positive review on it, thank you.image text in transcribedimage text in transcribedimage text in transcribed

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 arrav The inputted number should be between 0 and 1000 (inclusive) . Make sure your array is large enough to hold all the prime 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 o . You don't 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 You'll know if a number is evenly divisible by another number if the remainder of the division is O. Remember that the modulus (96) 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 (index 0) of another array Then, you 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 array process until every pair of opposite prime numbers has been multiplied and stored. Figure 1 and Figure 2 below demonstrate the process for an array with an even number of If the number of prime numbers is odd, then you will ignore the middle element. Figure 3 and Figure 4 demonstrate the odd process. prime numbers Prime number array for input 20 13 17 19 Product of extreme elements- 38 51 65 Total 4 Figure 1: Multiplications for an even number of prime numbers. Microsoft Visual Studio Debug Console nter a number between e-188e: 20 Total number of prime numbers found: 8 Total number of elements in the multiplication output array: 38 Figure 2: Output for an even mumber of prime numbers. Prime number array for input 25- 13 17 19 23 Product of extreme elements- 46 57 85 91 Total 4 Figure 3: Multiplications for an odd number of prime numbers. Microsoft Visual Studio Debug Console nter a number between e-188e: 25 Total number of prime numbers found: 9 tal number of elements in the multiplication output array: 4 Figure 4: Output for an odd number of prime numbers The code should have the following functions: A function that checks if a given number is prime or not * A function that performs the multiplication of all pairs of opposite prime numbers This function should have 3 input parameters: the prime array, the number of prime numbers, and an output array (to store the results of the multiplications) This function should return the number of elements in the multiplication output array o o Your main function should: Ask the user to enter the largest number to check for prime (0-1000) . o Make sure your code can handle the user entering any numbei Populate the prime number array by repeatedly calling the function that checks if a number is Print out the number of identified prime numbers followed by a list of them Print out the number of values in the multiplication output array followed by a list of themm .Create arrays of sufficient size to hold (1) the prime numbers and (2) the results of multiplication prime . Call the multiplication function to multiply all pairs of opposite prime numbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions