Algorithm sequence for change

In summary: So in your case, the previous line has A = 2. When you do A mod 10, it is the same as 2 mod 10, which gives you a remainder of 2.
  • #1
jonroberts74
189
0
only had a brief intro to algorithms like this

Given an amount of money A between.01 and .99, this determines the breakdown of A into quarters (q) dimes (d) nickels (n) pennies (p)


q:=A div 25
A:=A mod 25
d:= A div 10
A:= A mod 10
n:= A div 5
p:= A mod 5

I have to trace the algorithm for A=27
 
Physics news on Phys.org
  • #2
jonroberts74 said:
only had a brief intro to algorithms like this

Given an amount of money A between.01 and .99, this determines the breakdown of A into quarters (q) dimes (d) nickels (n) pennies (p)


q:=A div 25
A:=A mod 25
d:= A div 10
A:= A mod 10
n:= A div 5
p:= A mod 5

I have to trace the algorithm for A=27

So simply plug ##A = 27## in. Take note that the mod operator only works with integers.

##q := A/25 = 2##
##A := 27 \space mod \space 25 = 2##

Can you continue?
 
  • #3
q:=A div 25 =1
A:=A mod 25 = 2
d:= A div 10 = 2
A:= A mod 10 =5
n:= A div 5 = 5
p:= A mod 5 = 2

??
 
  • #4
jonroberts74 said:
q:=A div 25 =1
A:=A mod 25 = 2
d:= A div 10 = 2
A:= A mod 10 =5
n:= A div 5 = 5
p:= A mod 5 = 2

??

Yes sorry for the typo in my prior post. I meant ##q := 1##.

I have bolded where you have made a slight error. It should read ##A := 2 \mod 10 = 2##.

EDIT: Also, while it hasn't been mentioned yet, the line for ##p## should actually read something different. Is this for a programming class? If so the line for ##d## might also be wrong.
 
Last edited:
  • #5
The proper algorithm should be this regardless though:

A = 27

q:= A div 25 = 1
A:= A mod 25 = 2
d:= A div 10 = 0
A:= A mod 10 = 2
n:= A div 5 = 0
p:= A mod 1 = 2
 
  • Like
Likes 1 person
  • #6
Its for a discrete math class

why is it A:= 2 mod 10 = 2 ?

A becomes the value from the previous line??
 
  • #7
jonroberts74 said:
Its for a discrete math class

why is it A:= 2 mod 10 = 2 ?

A becomes the value from the previous line??

The mod operator gives you the remainder from doing a division.
so for example (% being the mod operator)
1%5 = 1
2%5 = 2
3%5 = 3
4%5 = 4
5%5 = 0
6%5 = 1 etc
 

What is an algorithm sequence for change?

An algorithm sequence for change is a step-by-step series of instructions that outlines the process for making a desired change. It is a systematic approach to solving a problem or achieving a specific outcome.

Why is it important to have an algorithm sequence for change?

Having an algorithm sequence for change ensures that the process is efficient and effective. It allows for a clear understanding of the steps involved and helps to identify any potential errors or roadblocks.

What are the key components of an algorithm sequence for change?

The key components of an algorithm sequence for change include a clear problem statement, a set of instructions or steps to follow, input and output variables, and a defined end goal.

How do you create an algorithm sequence for change?

To create an algorithm sequence for change, start by clearly defining the problem or desired outcome. Then, break down the problem into smaller steps and determine the logical order in which they should be executed. Test and refine the algorithm as needed.

What are some common challenges when creating an algorithm sequence for change?

Some common challenges when creating an algorithm sequence for change include identifying all necessary steps, ensuring the steps are in the correct order, and accounting for any potential errors or exceptions. It is also important to consider the efficiency and scalability of the algorithm.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
990
  • Programming and Computer Science
Replies
1
Views
622
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
15
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
Replies
3
Views
952
  • Precalculus Mathematics Homework Help
Replies
7
Views
660
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
3K
Back
Top