Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

string addition

0 views
Skip to first unread message

bediffere...@gmail.com

unread,
Mar 29, 2006, 12:19:06 PM3/29/06
to
I want to add Two string ranging from 2-50 char, which contains the
numeric values.


For Example
a[]={1,0,0,0,0,0,0,0,0,0...........0}
+ b[]={2,0,0,0,0,0,0,0,0,0...........0}
________________________________
c[]={3,0,0,0,0,0,0,0,0,0...........0}

Plz Help Me.

Vladimir S. Oka

unread,
Mar 29, 2006, 12:24:17 PM3/29/06
to
bediffere...@gmail.com opined:

These are not strings, but arrays of, presumably, `int`s.

Loop through them and add corresponding elements. Try to express that
in C, and if you have problems, come here for help. I doubt many
people here are willing to do your homework for you, and even if they
did, ask yourself whether it's going to do anything for your
knowledge. You are after knowledge, aren't you?

--
For large values of one, one equals two, for small values of two.

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Ivanna Pee

unread,
Mar 31, 2006, 10:20:04 AM3/31/06
to

I read string addiction

Me

unread,
Apr 1, 2006, 1:25:06 AM4/1/06
to

Addition's carry is either 0 or 1 (unless you're doing something
weird). Carry only occurs when all the terms are greater than the
maximum value. Putting all of this together:

T a[n], b[n], c[n+1];
...
T carry = a[i] + b[i] + oldcarry > maxvalue;

The above only works with math's unlimited range integers but not in
C's fixed range of integers (unless maxvalue is much less than T_MAX).
The way to work around this is to promote to a larger type (if one is
even available) or my preferred way of rearranging the terms:

T carry = a[i] > (maxvalue - oldcarry) - b[i];

If T is an unsigned integer, you can use (T)-1 for maxvalue, otherwise
you have to #include <limits.h> and use T_MAX.

0 new messages