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
A client reports the client has been experiencing increased stress at work. The client has been managing the stress by drinking
katovenus [111]

Answer:

d. The client has no adaptive coping mechanisms.

Explanation:

The reduction of anxiety felt by the clients is reduced by the Clients in either the functional ways or dysfunctional ways.

The first thing done by the nurse was to find out the techniques used by the client in past and help the client to enhance and identify those most beneficial strategies .The next step is done by the client and the nurse to find out the maladaptive strategies such as alcohol use,social withdrawal and swap them with adaptive strategies which are suitable for the client's cultural,personal and spiritual values.

The nurse should not suggest the client to give up coping mechanism without offering other mechanism even if the client is having the maladaptive strategies.

4 0
3 years ago
You have several reference computers. The computers are configured to always start from a local hard disk drive. You plan to cap
aivan3 [116]

Answer:

it is C.

Explanation:

3 0
3 years ago
Jeff has created a table to calculate the cost of raw materials that he purchases monthly. Cell A2 shows the fixed cost of the r
Luda [366]
=A2*D2
The above formula will allow calculation  of monthly cost of the first raw material.This is done by Multiplying the contents of cell A2 (Column A, Row 2) and cell D2 (Column D, Row 2). Here Cell A2 contains cost of the first raw material and Cell D2 contains number of units of the raw material produced  each month. After finding the monthly cost of the first raw material in this way, the monthly cost of other raw materials can simply be calculated by dragging down the formula to apply to the rows below.
3 0
3 years ago
Read 2 more answers
Please answer this question​
RSB [31]

Answer:

what is the other language

is it Assamese clarify me in the comment section bro

4 0
2 years ago
A string is represented as an array of characters. If you need to store an array of 5 strings with the maximum length of a strin
erastova [34]

Answer:

char str[5][100]

Explanation:

See attachment for options:

From the options, we can see that the programming language is C language.

The syntax to store an array of m strings with a maximum of n elements in C is:

char array-name[m][n]

In this case:

m = 5 --- Number of strings in the array

n = 100 --- Maximum character in each string

Assume the array name is str, the syntax can be expressed as:

char str[5][100]

3 0
2 years ago
Other questions:
  • The specifications for ____ are developed by the world wide web consortium (w3c) and are continually evolving.
    13·1 answer
  • What keyboard shortcut keys selects cell A1
    12·1 answer
  • kevin is working on a financial project that involves a lot of statistical information. He needs software that allows him to ent
    8·2 answers
  • Your car must have two red stoplights, seen from ______ feet in the daytime, that must come on when the foot brake is pressed.
    6·1 answer
  • Which of the following are examples of the concept of layered access in physical security? Select one: a. Firewall, IDS, CCTV b.
    11·2 answers
  • Which of the following are points that can demonstrate the accuracy of a website?
    6·1 answer
  • For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
    12·1 answer
  • Use the Law of Sines to solve the triangle. Round your answers to two decimal places.
    6·1 answer
  • I still haven't figured out how to award someone branliest will someone help me? If you explain to me how to do it i will do awa
    14·1 answer
  • Uh can somebody help me
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!