Write a function that determines whether a number is prime

Assignment Help Computer Engineering
Reference no: EM132169222

using html

9.19 An integer is said to be prime if it's greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not.

a) Write a function that determines whether a number is prime.

b) Use this function in a script that determines and prints all the prime numbers between 1 and 10,000. How many of these 10,000 numbers do you really have to test before being sure that you have found all the primes? Display the results in a <textarea>.

c) Initially, you might think that n/2 is the upper limit for which you must test to see whether a number is prime, but you need go only as high as the square root of n. Why?

Rewrite the program using the Math.sqrt method to calculate the square root, and run it both ways. Estimate the performance improvement.

Reference no: EM132169222

Questions Cloud

Create a chat client and chat server : Create a chat client, and chat server. The chat client must be able to communicate with other chat clients on separate computers on your local network.
Compute their time complexity in big-o notation : Write an implementation for each operation and compute their time complexity in Big-O notation (no justification is needed).
Write an application that creates objects of each of class : Write an application that creates objects of each of the three classes, places references to those objects in ArrayList .
Calculate the amount of county sales tax : A retail company must file a monthly sales tax report listing the total sales for the month, and the amount of state and county sales tax collected.
Write a function that determines whether a number is prime : Write a function that determines whether a number is prime. Calculate the square root, and run it both ways.
Create an automobile class for a dealership : Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed.
Write down the bit pattern that would represent : Using the IEEE 754 floating-point format, write down the bit pattern that would represent -1/4. Can you represent -1/4 exactly?
Create a text based version of the dice game button men : Create a text based version of the dice game 'Button Men'. No Special dice are allowed. Each Player starts with a set of 5 dice.
Display the percentages next to the displayed words : Input a second user-specified text file assumed to be a list of words, each on a separate line of text (no error checking for format).

Reviews

Write a Review

Computer Engineering Questions & Answers

  Identify three benefit of implementing server virtualization

Identify benefit of implementing server virtualization at the city of Seacliff Height. how specifically city will benefit by implementing server virtualization.

  Create a good design of functions to make best use of code

Create a good design of the functions to make the best use of the code and avoid duplicate calculations. You also need to design your program so that it has components that can be reused in another program, if needed.

  How can you handle above effect without adding another layer

How can you handle the above effect without adding another layer to your model?

  Design an error-logging system for an error-detecting memory

Whenever an error is detected, a low-priority interrupt is generated by the error detection circuit, and the operating system then makes a note of the location.

  Write down a 2- to 3-page paper which compares and

designing and coding a procedure module or object can be complex and time consuming. once these elements of a computer

  Write a program that calculates the amount of money

Write a program that calculates the amount of money a person would earn over a user-specified number of days if their salary is one penny the first day.

  Compare different intel processors in android devices

Compare and contrast the different Intel processors in Android phone and tablets. Practice converting between decimal and binary.

  What are the levels of physical security

With 200-400 words,atleast 2 references and also in apa format. What are levels of physical security and how do they differ in the amount of security needed?

  How to compute both the average

Write down a program that declares a vector of real numbers and input values until a 0 is entered. Add the values to the vector by using push_back(), and compute both the average and the maximum value of the numbers. Output the average and the max..

  What is the probability of a collision between packets

What is the probability of a collision between packets of the two piconets? Assume nodes are not using CSMA.

  What are some of the opportunities and challenges associated

The Consumer Electronics Show opened in January in Las Vegas. One of the major themes of the show was putting "intelligence" into physical products.

  What is a regular expression describes the grammar g

Construct a DFA that accepts/recognizes, strings derived from the grammar G with production rules.

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