Home / Expert Answers / Computer Science / write-an-algorithm-for-questions-2-and-4-the-first-image-shows-how-the-algorithm-should-be-structur-pa309

(Solved): Write an algorithm for questions 2 and 4. The first image shows how the algorithm should be structur ...



Write an algorithm for questions 2 and 4. The first image shows how the algorithm should be structured.

1. Other algorithms are possible.
\{integer, integer, integer, integer\}
change (real price)
amount \( =1,0- \) price
\( q=0

1. Other algorithms are possible. \{integer, integer, integer, integer\} change (real price) amount \( =1,0- \) price \( q=0 \) while amount \( \geq .25 \) \( \quad q=q+1 \) amount \( = \) amount \( -.25 \) \( d=0 \) while amount \( \geq .10 \) \( \quad d=d+1 \) amount \( = \) amount \( -.10 \) \( n=0 \) while amount \( \geq .05 \) \( n=n+1 \) amount \( = \) amount \( -.05 \) \( p= \) return \( \{q, d, \quad n, p\} \) end change 2. Write an algorithm that makes change for a purchase. The algorithm should return a set containing the number of quarters, dimes, nickels, and pennies to return (in that order). The return set should be declared as \{integer, integer, integer, integer\}. You may assume that the customer does not pay less than the price. Use as many quarters as necessary. 4. Write an algorithm that determines how many positive integers evenly divide the positive integer \( n \). The algorithm should return the number of divisors (not the actual divisors). For example, 4 has three divisors: 1,2 , 4. Call the algorithm numberofdivisors.


We have an Answer from Expert

View Expert Answer

Expert Answer


ALGORITHM changeForPurchase : Step 1: Take realPrice, paidByCustomer as parameters Step 2: set amo
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe