addition:
for nth digit in the array, starting from the least significant one,
z[n] = x[n]+y[n];
since z[n] is a digit, if z[n] turned out to be >= 10, subtract 10 from it and add 1 to z[n+1].
subtraction is the same thing, except that you check if x[n]-y[n] < 0 and then add 10 and subtract 1.
He's just saying that you should use an array of ints to hold each individual digit.
For example, to hold the value 2468, you'd have an array:
int num[4] = { 2, 4, 6, 8 };
To be able to add and subtract two such "numbers" you just have to think about how you would add and subtract two numbers with pencil and paper. Then go write the program to do it the same way.
UGLY WORKING CODE, at least for adding, you can use carry as overflow detection.
Substracting works only if X is bigger than Y.
If Z can have more digit than X and Y, you can avoid overflow.
After 2 days i need gave my homework to my teacher and he will give me the mark. and i need o complate this problem in his way. He showed me how does it has to start but i need to complate it. an someone help me to finish my program, here is the what he wrote;
n= 100
int x(100), Y(100), Z(101)
for (i=0, i<n,i++)
z[i]=x[i]+y[i]+c;
if (z[i]>9)
{c=1; z[i]=z[i]%10}
who can create a C++ program from this content. and plus i need to write it for z=x-y too
This is pretty much complete addition. Just put it in a function.
For subtraction change x+y+c to x-y-c and z>9 to z < 0 and z = z%10 to ...
Well, that % is kind of unneeded here (or in addition).. If you add two valid digits, the sum will be below 20 and if you subtract it will be above -10. You only need to add or subtract a 10 here to move the digit to it's correct value.