Question: Use c++ Goal In this assignment students will practice using stack to solve mathematical algorithms. Problems 1-(3 pts) A number n is prime if it

 Use c++ Goal In this assignment students will practice using stack
Use c++

Goal In this assignment students will practice using stack to solve mathematical algorithms. Problems 1-(3 pts) A number n is prime if it is only divisible by 1 or by itself. Write a function bool isPrime (int) that returns true if the number passed to it is prime and false otherwise 2- (7 pts) Each integer number >1 can be written as multiple of prime numbers. For example: 31212-17, 17,3,3,3, 2,2 To find an integer n prime factorization, one should keep dividing n by prime number i until n becomes 1 It was found that it is enough to divide n by only the prime numbers that are smaller or equal to its square root (no need to try all prime numbers smaller than n) Your program should start by asking the user to enter an integer number n. Start by choosing the first number i-2 and create a loop that goes from 2 to the square root of n. Test to check if the number i is prime (we are interested in only prime numbers that divide n) using the method you created in part 1. If i is prime, then test to see if it divides n. If i dividesrn and n is still greater than 1, push i on the stack and set n-n/i. Repeat the process until d is no longer divisible by i. Once n becomes non-divisible by i, move on to the next number by incrementingi and repeating the same process again. At the end, the stack has n prime factorization sequence. Create a Print method to print the stack

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!