1

Possible Duplicate:
“BigInt” in C?

Hi, I want to add & sub two large numbers like 1000000000000000000011 & 10000000000000000002311 using C programming. I know that we can only achieve by using character array. But I cant able to come up with an logic for doing it. So can anyone here help me out to solve this.

Community
  • 1
  • 1
CrazyCoder
  • 2,465
  • 8
  • 36
  • 57
  • not at all... trying to solve some puzzle on my own interest – CrazyCoder Jan 17 '11 at 09:07
  • Sorry for posting duplicate question but without any library is there a way to do it. – CrazyCoder Jan 17 '11 at 09:10
  • @Winbros - Reimplement your own version of the library. If you want to do this for learning purposes, by all means, go ahead, and ignore the people who complain about reinventing the wheel. – Chris Lutz Jan 17 '11 at 09:11
  • You could write your own library, but that seems like a waste of time since someone else already did it for you. – Cody Gray - on strike Jan 17 '11 at 09:12
  • 2
    @Winbros Do you remember how to add two numbers together on a piece of paper. You were probably taught this at elementary school. If you can remember how to do this, and you know how to program, then you'll be able to write a routine with ease. – David Heffernan Jan 17 '11 at 09:22
  • If you're insisting on doing it manually, the logic for doing so is called “long addition” (long, not `long`). You do it digit-wise with at most one carry digit, it's much easier if you keep the sequence of digits in least-significant-first order. – Donal Fellows Jan 17 '11 at 09:24
  • Given that this question is not asking for a bigint library but how to do it "manually", this question is not a duplicate of the one linked to. – JeremyP Jan 17 '11 at 09:58
  • I can't write an answer, because the question has been closed (wrongly), but think how you would do the sum using a pencil and paper. That will give you a starting point for the algorithm you need. – JeremyP Jan 17 '11 at 09:59
  • If the offered duplicate is unacceptable, try http://stackoverflow.com/questions/2217938/how-do-you-write-a-bigint-library-how-does-libgmp-work or http://stackoverflow.com/questions/3340511/what-is-the-simplest-way-of-implementing-bigint-in-c and for extra advice see http://stackoverflow.com/questions/3322551/what-is-an-efficient-way-to-convert-a-bignum-type-structure-to-a-human-readable-s and http://stackoverflow.com/questions/857070/how-to-convert-an-arbitrary-large-integer-from-base-10-to-base-16 and no doubt many others. – dmckee --- ex-moderator kitten Jan 18 '11 at 03:21

0 Answers0