Question: C++ 1. Create an integer array of 100 elements. Read numbers from the console and store them in the array until you read a zero.

C++

1. Create an integer array of 100 elements. Read numbers from the console and store them in the array until you read a zero. Keep a count of how many numbers you input (not including the final zero). You do not need to validate that the inputs are integers. Once all the numbers are entered, add them up. Display the sum and average, followed by listing the numbers five per line.

2. For this exercise, you will use a sieve of Eratosthenes to find the prime numbers less than 100. Create an array of 100 integers and initialize them all to 1. Then for each prime number up to 10 (2, 3, 5, 7) go through the array and mark any multiples of that number as not being a prime by changing its value to 0. (Start by setting locations 0 and 1 to zero). Finally, go through the array and print out the indices of all remaining elements that have a value of 1. These are the prime numbers less than 100. As a more advanced version, you could do this for all prime numbers less than 1000. Once you have gone through the array for 2 and 3, the next value with a 1 is the next prime and so forth.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!