Write a C++ program that lets the users enter positive integer numbers in a loop until...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a C++ program that lets the users enter positive integer numbers in a loop until the user enters a negative number. The program should check if the number entered is prime or not using a function. The function declaration is: bool isPrime (int n); where n is the integer to be checked. The function should return true if the number is a prime and false otherwise. A prime number is a number that is divisible by 1 and itself only. Examples of prime numbers are: 2, 3, 5,7, 11, 13, 17, 19, 23, 29, 31, etc. Sample Session: (Values in Green are entered by the user) Enter a positive integer (enter a negative integer to stop): 31 This is a prime number Enter a positive integer (enter a negative integer to stop): 16 This is not a prime number Enter a positive integer (enter a negative integer to stop): 22 This is not a prime number Enter a positive integer (enter a negative integer to stop): 43 This is a prime number Enter a positive integer (enter a negative integer to stop): -7667 Thank you! Write a C++ program that lets the users enter positive integer numbers in a loop until the user enters a negative number. The program should check if the number entered is prime or not using a function. The function declaration is: bool isPrime (int n); where n is the integer to be checked. The function should return true if the number is a prime and false otherwise. A prime number is a number that is divisible by 1 and itself only. Examples of prime numbers are: 2, 3, 5,7, 11, 13, 17, 19, 23, 29, 31, etc. Sample Session: (Values in Green are entered by the user) Enter a positive integer (enter a negative integer to stop): 31 This is a prime number Enter a positive integer (enter a negative integer to stop): 16 This is not a prime number Enter a positive integer (enter a negative integer to stop): 22 This is not a prime number Enter a positive integer (enter a negative integer to stop): 43 This is a prime number Enter a positive integer (enter a negative integer to stop): -7667 Thank you!
Expert Answer:
Answer rating: 100% (QA)
Heres a simple C program that fulfills the requirements includ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Kaye's Kitchenware has a market/book ratio equal to 1. Its stock price is $12 per share and it has 4.8 million shares outstanding. The firm's total capital is $130 million and it finances with only...
-
Listing 5.15 determines whether a number n is prime by checking whether 2, 3, 4, 5, 6, ..., n/2 is a divisor. If a divisor is found, n is not prime. A more efficient approach is to check whether any...
-
As CEO of your company, youve been going over your financial statements and have noticed something disturbing. You perform a horizontal analysis and find that sales have been increasing at a rate of...
-
How many members thought that the priority should be exactly one of the three issues? The 100 members of the Earth Club were asked what they felt the club's priorities should be in the coming year:...
-
In Exercises, find the open intervals where the functions are concave upward or concave downward. Find any inflection points. (x) = x(x + 5) 2
-
A bar magnet is enclosed by a spherical surface. (a) What is the magnetic flux through the entire surface? (b) If the magnetic flux through the hemisphere closest to the magnet's north pole is...
-
You are in charge of inventory control of a highly successful product retailed by your firm. Weekly demand for this item varies, with an average of 200 units and a standard deviation of 16 units. It...
-
1. Let p and q be two positive numbers such that p + q = 2 and p + q = 272. Then p and q are roots of the equation: (a) x-2x+8=0 2. lim x 0 (sint)dt (b) x-2x+136=0 (c) x-2x+16=0 (d) x-2x+2=0 0
-
Martha died this year with a net allowable capital loss for the year of death of $100,000. She had income from all sources of $5,000 in the year of death, $30,000 last year, and $27,000 two years...
-
Which one of these taxpayers (all filing single) would be the least likely to benefit from itemizing deductions? a. Maggie bought a house in January of 2019. As a result, she paid quite a bit in...
-
Students will read the "Evolution of Federal Interest" section in the textbook (13th Edition: Pages 236-239) and complete the following steps in their discussion post: 1. Provide a brief summary of...
-
A karaoke machine regularly costs $156 and is on sale for 25% off. How much is the discount? Show your calculations.
-
MTIR is evaluating the financial viability of a new project in Brazil. The firm utilises only two sources of financing: long-term debt and common equity. Its long-term debt ratio is 43%. The project...
-
( Sc < an Page 1: ! 1 T Module 5 Assessment Time Limit: 1:30:00 Time Left:1:23:08 A 1 4 50 DIL FI 2 5 3 6. @ 2 DEL * F2 W S (00 DIL 3 0 # Question 6 (17 points) Listen Quizzes... $1-12 $2-10 E...
-
The intercept coefficient means that children whose parents have average height zero would still have an expected height of 19 inches. Of course, this is not really meaning- ful. On the other hand,...
-
Please answer questions about noise: a) Please calculate the sound pressure level, in dB, of a noise with a sound pressure of 1 Pa. Imagine two workers who were exposed to occupational noise for 8...
-
A summary of changes in Pen Corporation's Investment in Sam account from January 1, 2011, to December 31, 2013, follows (in thousands): ADDITIONAL INFORMATION 1. Pen acquired its 80 percent interest...
-
Give the input and output variables for this program. Suppose that you are asked to write a program that computes the average (mean) of three numbers entered by the user.
-
If Name = "John", then Name >= "JOHN". True or False
-
A data file can be used by more than one program. True of False
-
Why does training sometimes fail?
-
What are the three major components in quality training recommended by Juran?
-
The Rocky Flats Plant of Rockwell International is committed to hiring hard-core unemployed people for entry-level positions with the intention of migrating them upward. However, many new employees...
Study smarter with the SolutionInn App