Question: 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

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!