Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 5 - Algorithms - Chapter Review Problems - Page 265: 23

Answer

The algorithm will print the prime numbers lass than 100

Work Step by Step

The algorithm uses a while loop from num to 99. flag is initialized to 0 for each num. The for loop checks if num is divisible by any i from 2 up to num/2. If divisible, flag = 1. After the loop, if flag == 0, num is printed. This effectively prints prime numbers, since primes are not divisible by any number other than 1 and themselves. num is incremented and the process repeats. The only issue is that the algorithm will print number $1$ also, which is not prime.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.