Write a program that prompts a user for n

Assignment Help Basic Computer Science
Reference no: EM131303684

The Sieve of Eratosthenes is an elegant algorithm for finding all of the prime numbers up to some limit n. The basic idea is to first create a list of numbers from 2 to n. The first number is removed from the list, and announced as a prime number, and all multiples of this number up to n are removed from the list. This process continues until the list is empty.
For example, if we wished to find all the primes up to 10, the list would originally contain 2, 3, 4, 5, 6, 7, 8, 9, 10. The 2 is removed and announced to be prime. Then 4, 6, 8, and 10 are removed, since they are multiples of 2. That leaves 3, 5, 7, 9. Repeating the process, 3 is announced as prime and removed, and 9 is removed because it is a multiple of 3. That leaves 5 and

The algorithm continues by announcing that 5 is prime and removing it from the list. Finally, 7 is announced and removed, and we're done.

Write a program that prompts a user for n and then uses the sieve algorithm to find all the primes less than or equal to n.

Reference no: EM131303684

Questions Cloud

Fixed costs of this product and variable costs per unit : Gork Musical Instruments produces several products, one of which is facing increasing competition from cheaper, plastic alternatives. It expects that in coming years the number of units sold will fall by 10% pa.  Gork expects that in the coming years..
Provide an analysis of technologies social implications : Social and ethical implications. Without disclosing your personal view about this technology, provide an analysis of its social and ethical implications.
Conduct sensitivity analysis for revenues : Conduct a sensitivity analysis for revenues by increasing revenues by 10% above the best estimate, and then by decreasing revenues by 10% below the best estimate. MAXIMIZE THE USE OF FORMULAS! The SCFE Co. wants to add a production line.
The relevant market interest rate for both bonds : Consider 2 bonds, A and B. The coupon rates are 10% and the face values are $1,000 for both bonds. Both bonds have annual coupons. Bond A has 20 years to maturity while Bond B has 10 years to maturity. What are the prices of the 2 bnds if the relevan..
Write a program that prompts a user for n : The algorithm continues by announcing that 5 is prime and removing it from the list. Finally, 7 is announced and removed, and we're done.
Calculate the tip displacement : Calculate the tip displacement by solving the total Lagrangian variational equation with the St. Venant-Kirchhoff nonlinear elastic material model.
Physicians on staff at metropolis health system : John Whitten is one of the physicians on staff at Metropolis Health System. His practice is six years old. He has set up an office savings account to accumulate the funds to replace equipment in his practice. Today John is trying to figure what his e..
Write short definitions for sexual reproduction : Write short definitions for Sexual reproduction, Asexual reproduction, Centromere, Metacentric, Submetacentric, Telocentric, Chromatids, Karyotype, Centrioles, Mitotic spindle, Crossing over and Prophase.
Find reaction force in the x2 direction at the top surface : Find the relation between k and Tx,- find the reaction force in the X2 direction at the top surface, and-  compare the results with that of the linear elastic model.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Communications with the host

How many bits internet address is assigned to each host on a TCP/IP internet which is used in all communications with the host?

  Design complete system of timer using 8086 and peripherals

Real-time systems often require precise timing for data sampling and control operations. This is usually achieved through the use of a programmable timer circuit that periodically interrupts the main processor at precise times.

  Do you obtain a good representation of the pareto frontier

Generate the Pareto frontier using the weighted sum method. Do you obtain a good representation of the Pareto frontier? Explain why or why not.

  What is the necessity of including idf in the weight

What is the necessity of including IDF in the weight of a term?

  Discuss the pros and cons of two information security

Discuss the pros and cons of two information security management models that would be appropriate for ChoicePoint to implement.

  What is a principal difference between them

. What does dynamic programming have in common with divide-and-conquer? What is a principal difference between them?

  Imperative devices on the planet today

Database applications are a standout amongst the most imperative devices on the planet today, particularly given the noteworthiness of information systems. Utilizing the Internet, books, magazines and different productions, discover the responses ..

  What is a predefined control event

What is a predefined control event? Discuss its usage in programming.

  Internet service provider

An Internet service provider has three different subscription packages for its customers: Package A: $9.95 per month for 10 hours access. Additional hours are $2.00 per hour Package B: $13.95 per month for 20 hours access. Additional hours are $1.00 ..

  Which team lost the world series each year

Which team lost the World Series each year

  Explain program manager for human services program

Write down 200- to 300-word email to friend describing new position and its responsibilities, incorporating all vocabulary words.

  Difference between traditional and industrial farming

difference between traditional and industrial farming

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd