Prime numbers can also be generated by an
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Programming in C
Additional Engineering Textbook Solutions
Digital Fundamentals (11th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
C++ How to Program (10th Edition)
Starting out with Visual C# (4th Edition)
Software Engineering (10th Edition)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education