A positive integer greater than 1 is said to be prime if it has no divisors...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Ivanhoe Company incurred research and development costs of $ 9 0 0 0 0 to develop a patent, and legal fees of $ 3 0 0 0 0 to register the patent. The patent has a legal life of 2 0 years and a useful...
-
Stahelin Valves produces a single component, a valve. The valve sells for $43 per unit. Fixed costs are $1,605,000 annually. Production and sales of 407,000 units annually results in profit before...
-
The following are trial balance of Clarissa Amanda Sdn. Bhd. as at 31st December 2021. Debit RM Credit RM Opening stock, 1 Jan 2021 16,000 Purchases 75,000 Sales return 5,000 Carriage inwards 1,500...
-
In Problems 11 54, simplify each expression. Assume that all variables are positive when they appear. 2 ( 5 29 )
-
A state runs a lottery in which 6 numbers are randomly selected from 40, without replacement. A player chooses 6 numbers before the states sample is selected. (a) What is the probability that the 6...
-
A refrigerator operates for a certain time, and the work done by the electrical energy during this time is W = 1000 J. What can be said about the heat delivered to the room containing the...
-
Air at standard temperature and pressure flows at a rate of 7.0 cfs through a horizontal, galvanized iron duct that has a rectangular cross-sectional shape of 12 in. by 6 in. Estimate the pressure...
-
The 21st Century Studios is about to begin the production of its most important (and most expensive) movie of the year. The movies producer, Dusty Hoffmer, has decided to use PERT/CPM to help plan...
-
The market portfolio of the Tierra del Fuego stock market has an expected return E r( ) M = 22% and a standard deviation of returns M = 19%. The risk-free rate is rf = 7%. a. What is the equation of...
-
The Fashion Rack has a monthly accounting period. All transactions are recorded in a general journal. Postings are made from the general journal to the accounts receivable ledger, accounts payable...
-
Suppose that the terms of trade between Mexico and the US are 3.5 tons of avocados in exchange for 1 ton of soybeans. Would the two countries be willing to trade at this relative price? Explain....
-
In below picture, the Temperature-Time-Transition (TTT) diagram for a glass forming material is shown: temperature T. m I 1 ppm 1% crystal time
-
1. Zachary Fox does not make any voluntary deductions that impact eamings subject to federal income tax withholding or FICA taxes. He has authorized voluntary deductions each pay period of $10 for...
-
Amazon Sales $177,866 Accounts receivable: Beginning of year 20,816 End of year 16,677 Determine the accounts receivable turnover. For interim computations, carry amounts out to one decimal place....
-
2. If a person seeks to report fraud related to a World Bank Group financed operation, to what department within the World Bank should that person direct their report? Describe the process of how the...
-
When a company lends money to employees at a rate of 4%, the company will record ______. Multiple choice question. a liability called Accounts Payable a liability called Notes Payable an asset called...
-
What are Iranians family traditions?
-
Chloroplasts are illuminated until the levels of the Calvin cycle intermediates reach a steady state. The light is then turned off. How does the level of RuBP vary after this point?
-
When do parties have the option of choosing conciliation, mediation, or arbitration?
-
Why are some unions philosophically opposed to raiding?
-
What is med-arb?
-
You are reviewing a tender evaluation that is to be awarded on lowest total price. The bid evaluations follow: To which company should the contract be awarded? Company Capital Cost Maintenance...
-
You are analyzing bids from two companies. Company A has scored 85 points on the quality evaluation (out of a scale of 100 points), while company B has scored 95 points. The overall weighting your...
-
A tender evaluation method specifies 30% price and 70% quality. What is the weighted score of a tender that scored 80 points (out of 100) for price and 60 for quality?
Study smarter with the SolutionInn App