Concept explainers
(The Sieve of Eratosthenes) A prime integer is any integer greater than 1 that can be divided evenly only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It works as follows:
- Create an array with all elements initialized to 1 (true). Array elements with prime indices will remain 1. All other array elements will eventually be set to zero.
- Starting with array index 2 (index 1 is not prime), every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose index is a multiple of the index for the element with value 1. For array index 2, all elements beyond 2 in the array that are multiples of 2 will be set to zero (indices 4, 6, 8, 10, and so on.). For array index 3, all elements beyond 3 in the array that are multiples of 3 will be set to zero (indices 6, 9, 12, 15, and so on.).
When this process is complete, the array elements that are still set to 1 indicate that the index is a prime number. Write a
Trending nowThis is a popular solution!
Chapter 6 Solutions
EBK C HOW TO PROGRAM
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++ from Control Structures to Objects (8th Edition)
- Jara, need to use array and method carrow_forward8. using c++, Write a function method that determines the mean of all the values in an array of integers. Your mean function should call a separate function that you write that determines the sum. Don’t use built-in sum or mean gadgets, but roll your own.arrow_forwardDeclare two characters array And take input from user in first array and at last index take slach zero (/0) similarly we take input in second array and at end /0. And take another array and copy first array in this blank array and when we come to /0 then copy second array in blank array. Example First array (this is a) Second array (book) Blank array (this is a book) Don't use built-in functionsarrow_forward
- Can you do the same problem but without class and just arrays?arrow_forwardwhat is Populating the array ?arrow_forward3. Write a program to find intersection of two sorted array.For example, if the two sorted arrays as input are {21, 34, 41, 22, 35} and {61, 34, 45, 21, 11}, it should returnan intersection array with numbers {34, 21}. For the sake of this Problem, you can assume that numbers ineach integer array are unique.arrow_forward
- Withour array pleasearrow_forwardWhat is the array index type? What is the lowest index? What is the representation of the third element in an array named a?arrow_forward4. Write a program to find kth smallest element in unsorted array?You are given an unsorted array of numbers and k, you need to find the kth smallest number in the array. Forexample if given array is {1, 2, 3, 9, 4} and k=2 then you need to find the 2nd smallest number in the array,which is 2.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning