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
  • In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13,...

    In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs whether the number...

  • (Done in Eclipse Java) 1. Given an integer between 1—100 captured from a user, perform the...

    (Done in Eclipse Java) 1. Given an integer between 1—100 captured from a user, perform the following conditional actions: • If is odd, print Weird • If is even and in the inclusive range of 2 to 5, print Not Weird • If is even and in the inclusive range of 6 to 20, print Weird • If is even and greater than 20, print Not Weird Note: Validate that your algorithm works for all cases. 2. Read an integer...

  • Write a program that finds and output all of the prime numbers between 2 to 2000...

    Write a program that finds and output all of the prime numbers between 2 to 2000 to the display screen. You are to declare any required array in main and pass them to your function sieve that will process the array.C++

  • Write a program that check odd / even numbers (from number 1 to 100). Display the...

    Write a program that check odd / even numbers (from number 1 to 100). Display the results within an HTML table with 2 columns: one for odd number and one for even numbers. NUMBERS RESULTS ODD EVEN ODD 2 HINT: use <table> tags to create a table, <th> tags for 'Numbers' and 'Results'. Wrap code PHP inside HTML code. For example: <html> <title>CHECK ODD or EVEN</title> <body> <table> ?php echo "<tr><td>l</td><td>Odd</td</tr>"; </table> </body </html 2. Do the following steps in...

  • The task involves writing a C++ program that determines the prime numbers between 1 and 100....

    The task involves writing a C++ program that determines the prime numbers between 1 and 100. The steps you should follow to identify the prime numbers are the following. 1. The number 1 is not a prime number, so it should be scratched. 2. Starting from the first prime number, which is 2, you scratch all the numbers that are the multiple of 2. You should not scratch out 2 itself. 3. The next number in the sequence after the...

  • Prime Number Programing in C Note: The program is to be written using the bitwise operation....

    Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...

  • For C++ program Your program should first prompt the user for the number of students they...

    For C++ program Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have...

  • Use phyton TheSieve of Eratosthonesis an algorithm to find all the prime numbers between 1 andsome integerN. It can be implemented with nestedforloops:(a) Make a list of all the integers from 2 throug...

    Use phyton TheSieve of Eratosthonesis an algorithm to find all the prime numbers between 1 andsome integerN. It can be implemented with nestedforloops:(a) Make a list of all the integers from 2 throughN.(b) Cross off all the multiples of 2 (except for 2 itself). The smallest number that remains(after 2) is 3.(c) Cross off all the multiples of 3 (except for 3 itself). The smallest number that remainsis 5.(d) Cross off all the multiples of 5 (except for 5 itself)....

  • write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.t...

    write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.txt and all output will go to the screen Assume there will not be more than 100 7 23.56 16 88.12 10 75.1 Design a Java class with a main method that does the following 1) Reads the data into two arrays of doubles,...

  • In C++ This program will read a group of positive numbers from three files ( not...

    In C++ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the scores in the order that they were input, showing each number and what percentage it is above or below the average for each file. Note: Finding the average doesn’t require an array. Finding...

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