Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Open the power_of_primes.cpp file and update the file to perform the following: (a) Prompt the user to enter a non-negative integer x and read the

Open the power_of_primes.cpp file and update the file to perform the following: (a) Prompt the user to enter a non-negative integer x and read the value (you are not required to check if the input is non-negative; just assume it is). (b) Write the logic which checks if x can be written as a power of two primes; that is, check if there exist two prime integers a and b such that x = ab. If you can write x as a power of primes, print \"Yes\" and print these primes that you found; otherwise, print \"No, x cannot be written as a power of primes\". Hints: An integer n is prime if n > 2 and n does not have any divisor other than 1 and itself. The logic for checking if an integer is prime or not is already given to you in the function is Prime which is provided above main (do not worry, you are not expected to understand the syntax because you did not learn about functions yet). Thus, you are not required to write the logic to check if a and b are prime; instead, you can directly use the given function. For example, you can write isPrime(a) to check if a is prime; this will give you a Boolean value: true if a is prime and false otherwise. (c) Ask the user to enter another integer N (assume it is positive), and print the first N positive integers which satisfy the condition in part b: for each one of these, print the corresponding primes (see the sample inputs/outputs below),

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

=+a. What is the 84th percentile?

Answered: 1 week ago