EBK C HOW TO PROGRAM
EBK C HOW TO PROGRAM
8th Edition
ISBN: 8220100663833
Author: Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 6, Problem 6.30E

(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:

  1. 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.
  2. 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 program that uses an array of 1,000 elements to determine and print the prime numbers between 1 and 999. Ignore element 0 of the array.

Blurred answer
Students have asked these similar questions
Is there a way to increase the size of an array after its declaration?
State whether the statement are true or false. If the answer is false, explain why? " If there are fewer initializers in an initializer list than the number of elements in the array , the remaining elements are initialized to the last value in the initializer list.
4. Given an array of ints, return the number of times that two 6's are next to each other in the array.int n[] = {2, 6, 71, 6, 6, 6, 34, 6, 6, 89}; C++

Chapter 6 Solutions

EBK C HOW TO PROGRAM

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
If a method in a subclass has the same signature as a method in the superclass, does the subclass method overlo...

Starting Out with Java: From Control Structures through Objects (6th Edition)

What is a loop iteration?

Starting out with Visual C# (4th Edition)

What is pseudocode?

Starting Out with Programming Logic and Design (4th Edition)

What is the difference between main memory and secondary storage?

Starting Out With Visual Basic (8th Edition)

The ___________ member function moves a files write position to a specified byte in the file.

Starting Out with C++ from Control Structures to Objects (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License