"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