Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Swift program to display first 100 prime numbers. Display 10 prime numbers per line. Prime number an integer greater than 1 is prime

Write a Swift program to display first 100 prime numbers. Display 10 prime numbers per line. Prime number an integer greater than 1 is prime if the only positive divisor is 1 or itself. For instance, 2, 3, 5 and 7 are prime numbers, but 4, 6, 8 and 9 are not. The program is to display the first 100 prime numbers in 10 lines, each line displays 10 prime numbers. The problem can be solved using loops: a. Set a loop counter to 0 and initial number to be tested to 2 b. Start loop iteration and determine whether the number is prime c. If the number is prime, display the number (on same line or next line) and increment the loop counter by 1 d. Increment the number by 1 e. Repeat steps b-d as long as the loop counter is 100 or less f. The loop terminates when the loop counter is greater than 100.

**You will need additional loops to determine whether the number is prime.

The output of this program

2 3 5 7 11 13 17 19 23 29

31 37 41 43 47 53 59 61 67 71

73 79 83 89 97 101 103 107 109 113

127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199 211 223 227 229

233 239 241 251 257 263 269 271 277 281

283 293 307 311 313 317 331 337 347 349

353 359 367 373 379 383 389 397 401 409

419 421 431 433 439 443 449 457 461 463

467 479 487 491 499 503 509 521 523 541

Program ended with exit code: 0

Make sure to apply the followings in your program:

Refer to swift code examples developed in-class and provided in the reading materials

Add comments in your code to document your program

Use descriptive and appropriate variable names/identifiers

Use named constant(s) appropriately

Have proper indentation and line spaces in your source code for readability

Have a HEADER comment block (to include your Name, Date created, Description/Purpose of the program)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions

Question

What four conditions are required for all types of databases?

Answered: 1 week ago