multiply large nos.

Discussion in 'C' started by mradul.exe, Jul 12, 2008.

  1. mradul.exe

    mradul.exe New Member

    Joined:
    Jul 12, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    can anybody tell me how to multiply two linked lists??

    i want to multiply large nos., consisting of hundreds of digit.
    i have stored the nos in link list form as one digit per node.
    now how to perform the multiplication???

    or

    is there any other way to multiply large nos???
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Ew, I wouldn't have chosen linked lists to implement a BigNumber library...

    I wrote my large number library using char* to represent numbers, reversed so that units were always str[0], tens str[1], 10^n's str[n]. e.g. 375 was stored as "573", 27 as "72".

    Multiplication worked along the lines of long multiplication that I did at school on paper:
    375
    27x
    ===
    2625 <- this line is 375*7
    7500 <- this line is 375*2*10
    ===
    10125 <- this line is the sum of the above two lines

    So to implement this you'll need functions to add (which you'll probably already have cos it's easy to add) and to multiply by a single digit. It shouldn't be impossible to do this with linked lists, if you really want to put yourself through that pain.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice