1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
umka21 [38]
2 years ago
8

Prime numbers can be generated by an algorithm known as the Sieve of Eratosthenes. The algorithm for this procedure is presented

here. Write a program called primes.js that implements this algorithm. Have the program find and display all the prime numbers up to n = 150.
Sieve of Eratosthenes Algorithm
To Display All Prime Numbers Between 1 and n
Step 1: We need to start with all the numbers representing the range of numbers that are possible candidate primes. So, create an array of consecutive integers from 2 to n: (2,3,4,..n). I wouldn't hand-code this. I would use a loop to populate the array.
Step 2: At each step we select the smallest number and remove all it's multiples. So we'll start with an outer loop that goes from 2 to n. initially, let p equal 2, the first prime number.
Step 3: In an inner loop we need to iterate over all the numbers that are multiples of p, i.e for 2, that's 2,4,6,8 etc. Each time, setting it's value to false in the original array.
Step 4: Find the first number greater than p in the list that is not marked False. If there was no such number, stop. Otherwise, let p now equal this number( which is the next prime), and repeat from step 3.
When the algorithm terminates, all the numbers in the list that are not marked False are prime
Example: Let us take an example when n = 50. So we need to print all print numbers smaller than or equal to 50. We create list of all numbers from 2 to 50.
2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
Computers and Technology
1 answer:
Sidana [21]2 years ago
4 0

Answer:

const MAXNR=150;

let candidates = {};

for(let i=2; i<=MAXNR; i++) {

   candidates[i] = true;

}

for(let p=2; p <= MAXNR; p++) {

   if (candidates[p]) {

       process.stdout.write(`${p} `);

       // Now flag all multiples of p as false

       i=2;

       while(p*i <= MAXNR) {

           candidates[p*i] = false;

           i++;

       }

   }

}

You might be interested in
Identify measures to protect your computer against threats from human actions. You cannot access a file in a computer that belon
scZoUnD [109]

Answer:

Firewalls

Explanation:

A firewall is simply a network security system whose main duty is. to prevent unwanted access to. private network.

Firewalls is measures to protect your computer against threats from human actions.

It is also the one singular thing that prevents you from accessing the file on your friends system.

5 0
3 years ago
Explain what the problems with the implementation of the function are, and show a way to fix them.// return true if two C string
Nataly [62]

Answer:

The code is not dereferencing the pointers. You have to place an asterisk in front of the pointer to read the value the pointer points to.

Explanation:

So "if (str1 != str2)" must be "if (*str1 != *str2)".

likewise:

   while (*str1 != 0 && *str2 != 0)

and

     result = (*str1 == *str2);

7 0
3 years ago
Tech a says that a direct tpms system uses a pressure sensor located in each wheel
Feliz [49]

Tech a says that a direct tpms system uses a pressure sensor located in each wheel. This is a TRUE statement.

Explanation:

  • A tire-pressure monitoring system (TPMS) is an electronic system designed to monitor the air pressure inside the pneumatic tires on various types of vehicles. A TPMS reports real-time tire-pressure information to the driver of the vehicle, either via a gauge, a pictogram display, or a simple low-pressure warning light.
  • Direct TPMS uses a sensor mounted in the wheel to measure air pressure in each tire. When air pressure drops 25% below the manufacturer's recommended level, the sensor transmits that information to your car's computer system and triggers your dashboard indicator light.
  • Mounted inside a tire assembly on valve stems or wheel rims, the sensors are usually powered by 3-volt lithium ion batteries, but some use 1.25-volt nickel metal hydride batteries. There are developments underway that promise battery-less sensors in the future, having the potential to dramatically change TPMS markets
  • The tire pressure monitor system that uses a valve-stem-type transmitter is the direct reading type of TPMS.

8 0
3 years ago
Controller Area Network CAN B bus diagnostics is being discussed. Technician A says some modules do not set specific codes that
miss Akunina [59]

Answer:

Both Technician A and Technician B is correct.  

Explanation:

CAN (Controller Area Network) is specially designed for the European cars and the automotive industry, but it has become the popular bus in the industrial automation and also in other applications.  

CAN is the serial communication bus that is designed for flexible and robust performance in a harsh environment.

3 0
3 years ago
Are Microsoft an Apple more secure from malicious action because of their closed-source approach?
omeli [17]

Yes Microsoft and Apple used the closed-source approach to better secure from malware and make to make their operating systems more user friendly.

7 0
3 years ago
Other questions:
  • For all those among our fans and SpongeBob fans which is better SpongeBob or amount us
    11·2 answers
  • "what windows process is responsible for authenticating users?"
    12·1 answer
  • / List the seven basic internal components found in a computer tower.
    5·2 answers
  • ____ is another term for document properties.
    12·1 answer
  • The mathematical constant Pi is an irrational number with value approximately 3.1415928... The precise value of this constant ca
    12·1 answer
  • Psychographics may also be called A. personality analytics. B. social group dynamics. C. lifestyle analysis. D. opinion insight.
    6·1 answer
  • The master production schedule for Product A shows a need for 30 units, and Product B shows a need of 25 units. To manufacture a
    12·1 answer
  • Which skill type refers to the knowledge and ability to perform a task?
    13·2 answers
  • Encryption is an important topic in math and computer science. It keeps your personal information safe online.
    6·1 answer
  • What is the median of 6, 16, 9, 20, 45, 30, and 32?<br> A. 9<br> B. 16<br> C. 20<br> D. 22
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!