Question: Write a program that determines and prints out the prime numbers between and including 1 and 239. Use a loop to increment a variable in

Write a program that determines and prints out the prime numbers between and including 1 and 239. Use a loop to increment a variable in the manner: 1, 2, 3, etc. Within the loop, use another loop to divide the variable by: 1, 2, 3, etc. up to the current value of the variable. A prime number is a number that is evenly divisible only by 1 and itself, therefore, if a number is evenly divided by a value between 1 and itself, it is not prime. You will find the % (modulus) operator useful. The modulus is the remainder after division (example: 7 % 3 = 1). If the modulus is 0 the first number is evenly divisible by the second number. The output might look something like: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 (etc.) On the next page there is a flowchart of the algorithm showing one approach to the program logic. Note the nested loop. C++ format in codeblocks or notepad format

Write a program that determines and prints out the prime numbers between

NO NO n 1 is prime x 1 YES n MOD x Y 0? YES is prime is prime 12 NO 239? YES STOP NO YES print n

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!