Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to add two no. of 100 digits or more?

Reply
Thread Tools

how to add two no. of 100 digits or more?

 
 
Umesh
Guest
Posts: n/a
 
      05-30-2007
Is there any way by which i can do it? Thanks.

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-30-2007
Umesh wrote:
> Is there any way by which i can do it? Thanks.
>

Yes

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Quentin Godfroy
Guest
Posts: n/a
 
      05-30-2007
On May 30, 3:53 am, Umesh <(E-Mail Removed)> wrote:
> Is there any way by which i can do it? Thanks.


Link with a library which does that.

 
Reply With Quote
 
Sanchit
Guest
Posts: n/a
 
      05-30-2007
On May 30, 1:00 pm, Ian Collins <(E-Mail Removed)> wrote:
> Umesh wrote:
> > Is there any way by which i can do it? Thanks.

>
> Yes
>
> --
> Ian Collins.


But howwwwwwwwwwwwwwwwwww????????????????????????????? ????

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-30-2007
Sanchit said:

> On May 30, 1:00 pm, Ian Collins <(E-Mail Removed)> wrote:
>> Umesh wrote:
>> > Is there any way by which i can do it? Thanks.

>>
>> Yes
>>
>> --
>> Ian Collins.

>
> But howwwwwwwwwwwwwwwwwww????????????????????????????? ????


Well, he says he's Sanchit, but he's acting like Umesh.

Into the killfile with him.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
Reply With Quote
 
Sanchit
Guest
Posts: n/a
 
      05-30-2007
On May 30, 3:32 pm, Richard Heathfield <(E-Mail Removed)> wrote:
> Sanchit said:
>
> > On May 30, 1:00 pm, Ian Collins <(E-Mail Removed)> wrote:
> >> Umesh wrote:
> >> > Is there any way by which i can do it? Thanks.

>
> >> Yes

>
> >> --
> >> Ian Collins.

>
> > But howwwwwwwwwwwwwwwwwww????????????????????????????? ????

>
> Well, he says he's Sanchit, but he's acting like Umesh.
>
> Into the killfile with him.
>
> --
> Richard Heathfield
> "Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
> email: rjh at the above domain, - www.


I am Sanchit only..... not umesh..... So I want to know how can i do
this.... can anyone tell me this

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-30-2007
Sanchit wrote:
> On May 30, 3:32 pm, Richard Heathfield <(E-Mail Removed)> wrote:
>> Sanchit said:
>>
>>> On May 30, 1:00 pm, Ian Collins <(E-Mail Removed)> wrote:
>>>> Umesh wrote:
>>>>> Is there any way by which i can do it? Thanks.
>>>> Yes
>>>> --
>>>> Ian Collins.
>>> But howwwwwwwwwwwwwwwwwww????????????????????????????? ????

>> Well, he says he's Sanchit, but he's acting like Umesh.
>>
>> Into the killfile with him.
>>

*Please* don't quote people's signatures.
>
> I am Sanchit only..... not umesh..... So I want to know how can i do
> this.... can anyone tell me this
>

Use an arbitrary precision library.

--
Ian Collins.
 
Reply With Quote
 
Robbie Hatley
Guest
Posts: n/a
 
      05-30-2007

"Umesh" <(E-Mail Removed)> wrote:

> Is there any way by which i can do it?


Is there any way you can do *WHAT*?

Oh, I see you put most of your message body in the
"Subject" header again. Tsk, tsk.

I just got through writing functions to add, subtract, and
multiply integers of up to two billion digits. (The greatest
expressible number is well over 10^2000000000, which, in case
you don't realize, is so big it's no longer "astronomical".
Astronomy doesn't use numbers anywhere near that large.
Combinatorial analysis, however, does.)

Alas, though, my functions are in C++, not C.

Basically, use strings of digits to represent the decimal
expansions of integers. Do arithmetic manually on the
individual digits, just like you do when adding numbers
with pencil and paper. Don't forget to carry when the
sum of any two digits (plus previous carry) is > 9.

For what it's worth, the following may give you an idea of
the algorithm you need. I'm afraid you'll have to translate
it to C and intuit the unresolved references yourself.
(If it doesn't make any sense to you, google "addition algorithm".)

rhmath::BigNum rhmath:perator+(const BigNum& a, const BigNum& b)
{
if ( a.neg() && !b.neg()) {return (( b)-(-a));} // could go either way
if (!a.neg() && b.neg()) {return (( a)-(-b));} // could go either way
if ( a.neg() && b.neg()) {return -((-a)+(-b));} // always negative

// If we get to here, a and b are both non-negative integers.

// Get sizes of a and b:
long a_size = a.str().size();
long b_size = b.str().size();

// Get necessary size for C:
long C_size = 1;
if (a_size > C_size) {C_size = a_size;}
if (b_size > C_size) {C_size = b_size;}
C_size += 1;

// Make a string of 0s of length C_size:
std::string C (C_size, '0');

register long i = 1;
register int accum = 0;
register int carry = 0;

while ( i <= C_size )
{
// Reset Accumulator:
accum = 0;

if (i <= a_size) accum += ctoi(a.str()[a_size - i]);
if (i <= b_size) accum += ctoi(b.str()[b_size - i]);
if (carry > 0)
{
accum += carry;
carry = 0;
}

// If overflow occured, transfer overflow to carry:
while (accum > 9) {carry += 1; accum -= 10;}

// Insert character representation of accumulator in C:
C[C_size - i] = itoc(accum);

// Move on to next-higher place value:
++i;
}
return BigNum (C);
}

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org


 
Reply With Quote
 
etherzhhb@gmail.com
Guest
Posts: n/a
 
      05-30-2007
On May 30, 3:53 pm, Umesh <(E-Mail Removed)> wrote:
> Is there any way by which i can do it? Thanks.


I think you can reference the book << Numerical Recipes in C:The Art
of Scientific Computing,Second Edition>>.

 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      05-30-2007
On May 30, 12:53 am, Umesh <(E-Mail Removed)> wrote:
> Is there any way by which i can do it? Thanks.


Use one of these thingies:
http://www.medicis.polytechnique.fr/...mings-220.html

A web search will turn up stuff like this in just a few keystrokes and
hey -- no waiting. Better yet, no punching bag duty for off-topic
questions.

IMO-YMMV.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Tetration (print 100^100^100^100^100^100^100^100^100^100^100^100^100^100) jononanon@googlemail.com C Programming 5 04-25-2012 08:49 PM
100% TABLE + 100% ROW + 100% DIV..? fred Javascript 3 03-17-2005 04:25 AM



Advertisments