Question: Swift 4 code You will write code to look for primes in a small range; for example, display all primes less than a maximum of

Swift 4 code

You will write code to look for primes in a small range; for example, display all primes less than a maximum of a few thousand.

Below is a rough verbal description of the algorithm you will implement (maxInt is the largest number to be considered for prime-ness) to look for primes:

create an array of maxInt booleans and initialize each to true.

for each number 2 to sqrt(maxInt), "cross out" all the multiples of that number (i.e. set them to false - they are not prime) in the array. So array[4] = false, array[6] = false... and then array[6] = false, array[9] = false...

when you are done, those array elements that are still true are primes (do not report 0 or 1 as prime). Background You will recall that a prime number is a number that cannot be divided evenly by any numbers other than itself and 1. So, for example, 5 is prime because it can only be divided by 5 and 1. 6 is not prime since it can be divided by 2 and 3 as well as by 6 and 1. 1 itself is not considered prime. The prime numbers less than 25 are: 2, 3, 5, 7, 11, 13, 17, 19, and 23. Prime numbers are very interesting mathematically. The largest known prime has about 16 million digits. Part One: Use Xcode 9.1 or 9.2 to create a new playground, named YourLastName_PrimesCoder.

Write Swift 4 code to find primes for a given integer greater than or equal to 25 using the provided algorithm.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!