Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer

A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A Use the following numbers to test (Only type in the red numbers as input): Sample Input Enter an integer

A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that asks the user to enter an integer greater than 1, then displays all of the prime numbers that are larger than 1 and less than or equal to the number entered, and displays then displays all of the composite numbers that are larger than 1 and less than or equal to the number entered. The program should work as follows: Write a function named q1() with no parameters and no return value Inside function q1(). 1. Include a function which asks user to enter an integer and validate user's input. If user's input is not greater than 1, then ask user input again, until user enter a valid number, returns that number. (Use a while loop for this.) 2. Include a function which takes an integer parameter and returns prime if the argument is a prime number, or returns composite if the argument is a composite number. 3. Include a function which takes a list as the parameter and returns all the prime numbers among the list. The list contains numbers between 2 and the integer input that was read earlier. 4. Include a function which takes a list as the parameter and returns all the composite numbers among the list. The list contains numbers between 2 and the integer input that was read earlier. 5. You may include other functions inside q1() if it is needed. 6. You should call these functions in your program to get the input. The output of q1() is the list of prime numbers and the list of composite numbers. Use the following numbers to test (Only type in the red numbers as input): Use the following numbers to test (Only type in the red numbers as input): Sample Input Enter an integer greater than 1:23 Enter an integer greater than 1:0 Expected Output The prime number list: [2, 3, 5, 7, 11, 13, 17, 19, 23] The composite number list: [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 221 Invalid input

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

Industrial Relations in Canada

Authors: Fiona McQuarrie

4th Edition

978-1-118-8783, 1118878396, 9781119050599 , 978-1118878392

More Books

Students also viewed these Programming questions

Question

Why are some unions philosophically opposed to raiding?

Answered: 1 week ago

Question

What is med-arb?

Answered: 1 week ago