1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Algorithm sequence for change

  1. Jul 5, 2014 #1
    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
     
  2. jcsd
  3. Jul 5, 2014 #2

    Zondrina

    User Avatar
    Homework Helper

    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?
     
  4. Jul 5, 2014 #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

    ??
     
  5. Jul 5, 2014 #4

    Zondrina

    User Avatar
    Homework Helper

    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: Jul 5, 2014
  6. Jul 5, 2014 #5

    Zondrina

    User Avatar
    Homework Helper

    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
     
  7. Jul 5, 2014 #6
    Its for a discrete math class

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

    A becomes the value from the previous line??
     
  8. Jul 7, 2014 #7
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Algorithm sequence for change
  1. Algorithm help (Replies: 1)

  2. Greedy Algorithm (Replies: 0)

  3. FindKth algorithm (Replies: 2)

  4. Algorithm Help (Replies: 4)

Loading...