Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.

Create a C++ program that utilizes nested for loop that asks the user for a number then the program should compile a list of all natural numbers from 2 to the number the user keyed in marking with a star the prime numbers only.

1. Asks the user for number.

2. List all numbers from 2 to the user typed number.

3. Mark the Prime number with a stars leaving the composite numbers not labeled.

4. Stars should increment keeping track of the prime numbers found previously.

5. In case no Prime numbers is found your program should notify the user.

6. Make sure to check your program for values over 180.

Example Run:

PLEASE ENTER A NUMBER: 1

** NO PRIME NUMBERS WERE FOUND

DO YOU WANT TO TRY AGAIN (Y/N)? y

PLEASE ENTER A NUMBER: -23

** Negative integers cant be prime, try using positive values

DO YOU WANT TO TRY AGAIN (Y/N)? y

PLEASE ENTER A NUMBER: 15.6

** No floating point is allowed try whole numbers only

DO YOU WANT TO TRY AGAIN (Y/N)? y

PLEASE ENTER A NUMBER: 28

2 *

3 **

4

5 ***

6

7 ****

8

9

10

11 *****

12

13

14

15

16

17 ******

18

19 *******

20

21

22

23 ********

24

25

26

27

28

FOUND 8 PRIME NUMBERS

DO YOU WANT TO TRY AGAIN (Y/N)? n

Thank you goodbye ...

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

More Books

Students also viewed these Databases questions