Results 1 to 7 of 7

Math Help - Dividing

  1. #1
    borg_brain
    Guest

    Dividing

    Ok I know the title makes it sound easy but that’s not the point.

    The problem I’ve got is actually computer related but with a maths twist. I have a very basic programming language which has only the Add and Subtract functions, I've made a working multiply function but it only deals with whole numbers as does the whole program.

    So anyway is there a method of dividing using only add and subtract and whole number multiplication. I don't know if this is making any sense it started playing with my head so sorry. But if anyone can help that would be great.


    Martin
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor

    Joined
    Aug 2006
    Posts
    18,803
    Thanks
    1692
    Awards
    1
    Perhaps you should tell us what you did to define multiplication.
    Do you understand that division is the inverse of multiplication?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    is up to his old tricks again! Jhevon's Avatar
    Joined
    Feb 2007
    From
    New York, USA
    Posts
    11,663
    Thanks
    3
    Quote Originally Posted by borg_brain View Post
    Ok I know the title makes it sound easy but that’s not the point.

    The problem I’ve got is actually computer related but with a maths twist. I have a very basic programming language which has only the Add and Subtract functions, I've made a working multiply function but it only deals with whole numbers as does the whole program.

    So anyway is there a method of dividing using only add and subtract and whole number multiplication. I don't know if this is making any sense it started playing with my head so sorry. But if anyone can help that would be great.


    Martin
    indeed. we can actually think of division as a weird form of subtraction, or more appropriately, counting a certain number of subtractions. for example: 12 divided by 2 is 6. why? because we can subtract 2 from 12 6 times.

    if your program can do "loops" this shouldn't be too hard for you to code. (note, i am not in the least adept at programming, but i've heard people talk about algorithms before, so i'll describe an algorithm to you).

    Algorithm for calculating a \div b

    Let counter = 0 and remainder = 0

    if b = 0

    ..........print: a \div b is undefined

    else

    ..........if a < b
    ....................print: a \div b = a/b

    (and you can program it to output in decimal if you want, so if a = b you will get 1)

    .........else

    ...................while a > b, do:

    ...........................remainder = a - b
    ...........................counter = counter + 1
    ...........................a = remainder

    ...................end while loop

    ...................print: a \div b = counter " and " remainder/b


    .........end if

    end if


    so basically this algorithm counts the number of times you can subtract b from a, and also keeps track of the remainder when doing so. as long as the remainder is greater than zero and a is greater than b, it will keep subtracting and keep counting. in the end, the result will be the number of counts we have plus the remainder over the dividend. (at least that's what the program is supposed to do. you figure out the details, like i said, i'm not a programmer)
    Follow Math Help Forum on Facebook and Google+

  4. #4
    is up to his old tricks again! Jhevon's Avatar
    Joined
    Feb 2007
    From
    New York, USA
    Posts
    11,663
    Thanks
    3
    Quote Originally Posted by Plato View Post
    Perhaps you should tell us what you did to define multiplication.
    Do you understand that division is the inverse of multiplication?
    indeed, but how would you code something like that? i can visualize an algorithm using subtraction in my head, but i'm a little confused as to how to tell a computer to do the inverse of multiplication

    o wait, i got an idea just now while typing this, i'll think about it some more.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor

    Joined
    Aug 2006
    Posts
    18,803
    Thanks
    1692
    Awards
    1
    Quote Originally Posted by Jhevon View Post
    indeed, but how would you code something like that?
    Just as you did above: if we add to multiply then subtract to divide.
    But note that he/she did say that these are whole numbers, no decimals.
    So while multiplication has no restrictions, division does have restrictions.

    I wanted to see what code he/she had. I think there is some shorter code using while and until.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    is up to his old tricks again! Jhevon's Avatar
    Joined
    Feb 2007
    From
    New York, USA
    Posts
    11,663
    Thanks
    3
    Quote Originally Posted by Plato View Post
    Just as you did above: if we add to multiply then subtract to divide.
    But note that he/she did say that these are whole numbers, no decimals.
    So while multiplication has no restrictions, division does have restrictions.

    I wanted to see what code he/she had. I think there is some shorter code using while and until.
    oh, ok. i wasn't thinking of the multiplication function as addition in terms of the code. since he already coded multiplication, i suppose there would have been a new function called a*b or something like that, with addition built in it, but is not really explicit
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor

    Joined
    Aug 2006
    Posts
    18,803
    Thanks
    1692
    Awards
    1
    Here is one way using only addition.
    Define a function as: D(J,K), J divides K.
    D(J,K)
    N:=0; Q:=0
    While N<K
    N:=N+J; Q:=Q+1
    Loop

    If N=K print Q else print “not divisible”.

    Now this is only for positive integers.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Dividing Polynomials
    Posted in the Algebra Forum
    Replies: 1
    Last Post: September 17th 2009, 09:41 AM
  2. Dividing into even groups
    Posted in the Statistics Forum
    Replies: 2
    Last Post: September 11th 2009, 08:39 AM
  3. dividing
    Posted in the Pre-Calculus Forum
    Replies: 6
    Last Post: July 17th 2009, 10:23 AM
  4. Dividing
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: March 19th 2009, 11:07 PM
  5. dividing
    Posted in the Algebra Forum
    Replies: 2
    Last Post: November 29th 2008, 12:29 PM

Search Tags


/mathhelpforum @mathhelpforum