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
ipn [44]
3 years ago
9

To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: 1. Create a list of consecutive i

ntegers from two to n: (2, 3, 4, ..., n), 2. Initially, let p equal 2, the first prime number, 3. While enumerating all multiples of p starting from p2, strike them off from the original list, 4. Find the first number remaining on the list after p (it's the next prime); let p equal this number, 5. Repeat steps 3 and 4 until p2 is greater than n. 6. All the remaining numbers in the list are prime.

Computers and Technology
1 answer:
natta225 [31]3 years ago
7 0

Answer:

I am writing a Python program:

def Eratosthenes(n):  

   primeNo = [True for i in range(n+1)]  # this is a boolean array

   p = 2  # the first prime number is initialized as 2

   while (p * p <= n):     # enumerates all multiples of p

       if (primeNo[p] == True):                

           for i in range(p * p, n+1, p):  #update multiples

               primeNo[i] = False

       p = p + 1        

   for p in range(2, n):   #display all the prime numbers

       if primeNo[p]:  

           print(p),    

def main():     #to take value of n from user and display prime numbers #less than or equal to n by calling Eratosthenes method

   n= int(input("Enter an integer n: "))

   print("The prime numbers less than or equal to",n, "are: ")  

   Eratosthenes(n)      

main()      

Explanation:

The program contains a Boolean type array primeNo that is initialized by True which means that any value i in prime array will be true if i is a prime otherwise it will be false. The while loop keeps enumerating all multiples of p starting from 2, and striking them off from the original array list and for loops keep updating the multiples. This process will continue till the p is greater than n.  The last for loop displays all the prime numbers less than or equal to n which is input by user. main() function prompts user to enter the value of integer n and then calls Eratosthenes() function to print all the prime numbers less than or equal to a given integer n.

   

You might be interested in
Given an int variable n that has already been declared and initialized to a positive value , and another int variable j that has
Ugo [173]
While( n )  /*when n == 0, will fail*/
{
   putchar( '*' );  /*effectively print asterick*/
   n--;    /*post-decrement n*/
}
8 0
3 years ago
__________ is an attempt to gain access to a network by posing as an authorized user in order to find sensitive information, suc
laila [671]
Spoofing is<span> an attempt to gain access to a network by posing as an authorized user in order to find sensitive information, such as passwords and credit card information. </span>
8 0
3 years ago
Scientists measure an object’s mass in kilograms and its weight in newtons. If you knowthe amount of mass of an object in kilogr
Phoenix [80]

Answer:

public class WeightCalculator {

   

   private static DecimalFormat df2 = new DecimalFormat("#.##");

   

   public static void main(String args[]){

       //create scanner to receive user input

       Scanner in = new Scanner(System.in);

       //alert user to input mass

       System.out. println("Enter the Mass in Kg");

       //collect the input as a string

       String s = in. nextLine();

       //convert string to double and multiply by 9.8

       Double weight = Double.valueOf(s)* 9.8;

       

       //Print out answer formatted to 2 decimal place

       System.out. println("The Weight is " + df2.format(weight) + "N");

       

       //conditional statement to check if weight is less than 100

       if (weight < 100){

           System.out. println("Oops, it is too light");

       }

       //conditional statement to check if weight is more than 500

       if (weight > 500){

           System.out. println("Oops, it is too heavy");

       }            

   }

}

7 0
4 years ago
Really need help with these PLZ
snow_lady [41]

1. B joint application design

2. A it is necessary to write most of the new code manually

3. D since users have been involved in the pro typing, managers can be confident that the system can handle large numbers of users

4. B extreme programming

5. C code that is produced using OOD is easy to secure

6. A more testing is preferable to less testing

7. C object-oriented development

8. D component-based development

9. A object

10. B the code can only represent information as objects

4 0
3 years ago
The database cannot be migrated to a different engine because sql server features are used in the application’s net code. The co
Nezavi [6.7K]

Answer:

Explanation:

B is correct

3 0
2 years ago
Other questions:
  • You will use the _____
    15·2 answers
  • How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
    13·1 answer
  • 3k means about 3 thousand bytes. how would you express two hundred million bytes? .
    8·1 answer
  • python Write a program that will take a file named Celsius.dat that contains a list of temperatures in Celsius (one per line), a
    9·1 answer
  • Assignment 1 is to write a program that will write the lyrics to "X number of beers on the wall". Use only the main method. Prom
    11·1 answer
  • Join for a pack battle loud microphone.
    10·1 answer
  • Used for monitoring web activity by users to make sure that sensitive information won't leave the building.
    7·1 answer
  • What happens when i expose a disk to magnetic fields?​
    5·1 answer
  • Kyle has a notebook for each of his 5 classes. He puts 6 stickers on each notebook. There are 10 stickers on each sheet. How man
    11·2 answers
  • In java language I want the code
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!