Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 6, Problem 7E

Prime numbers can also be generated by an algorithm known as the Sieve of Eratosthenes. The algorithm for this procedure is presented here. Write a program that implements this algorithm. Have the program find all prime numbers up to n= 150. What can you say about this algorithm as compared to the ones used in the text for calculating prime numbers?

Sieve of Eratosthenes Algorithm

To Display All Prime Numbers Between 1 and n

Step 1: Define an array of integers P. Set all elements Pi to 0, 2 <= i <= n.

Step 2: Set i to 2.

Step 3: If i > n, the algorithm terminates.

Step 4: If Pi is 0, then i is prime.

Step 5: For all positive integer values of j, such that i x j≤ n, set Pixj to 1.

Step 6: Add 1 to i and go to step 3.

Blurred answer
Students have asked these similar questions
Python Write a Python program that performs a linear (sequential) search. Define an array of 10 non-sequential numbers. Ask the user for a number, such as "Enter a number to be found:" Search the array for the user's number. If present, display "Successful search, the element is found at position " and its position. Otherwise, display "Number not found."
Exercise 1:  Write a program that generates a sequence of 20 random values between 0 and 99 in an array, prints the sequence, sorts it, and prints the sorted sequence. Use the sort method from the standard Java library.   Exercise 2:    Write a program that stores a list of countries:  "Egypt", "Switzerland", "Argentina", "Spain", "Portugal", "Luxemburg", etc.  Initialize your array with a single statement.  Then print out the array.  Use the sort function as before to sort the countries in alphabetical order. Reprint your array.  Exercise 3:  Implement exercises 1 and 2 using ArrayList.  Use the  Collections.sort method for sorting.  After you have printed and sorted your results,  then append an additional element to each list and reprint your ArrayLists.   Notice that the new items will appear just at the end and will not be sorted.   Resort and print out the new ArrayLists again.   To clarify, you should print out your ArrayLists after your first sort, after adding items with the…
Create a array of size n and poulate it with random numbers in range @ to 150. Print the maximum number in the array. Take n as input by user. Write whole code in main function only.Given n>=1 and n

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License