On beginning I define two arrays
a[5];
b[5];
after this I need next array C
c[5];
but when I have c[5] = a[5] + b[5]
I have overflow of array C.
how can I change length of array C in loop, I don't change C if I don't have overflow
On beginning I define two arrays
a[5];
b[5];
after this I need next array C
c[5];
but when I have c[5] = a[5] + b[5]
I have overflow of array C.
how can I change length of array C in loop, I don't change C if I don't have overflow
It would be c[4] = a[4] + b[4].
Remember that arrays in C begin with index 0, so array[5] gives you indeces 0-4 only.
I know that a[0] is first element of array
I have need for something like this:
that mean c[i+1] = a[i] + b[i]Code:a[5] = {9,9,9,9,9,9} + b[5] = {8,8,8,8,8,8} = c[5+1] = {1,8,8,8,8,8,7}
but 1 in [i+1] is conditioned by add, it not always present
in this case I don't have need for +1 in c[i]Code:a[5] = {4,4,4,4,4,4} + b[5] = {4,4,4,4,4,4}; = c[5] = {8,8,8,8,8,8};
Set the length of array c to be 6 and, in cases where the length of the result is 5, make the first element zero.
define array c longer length.
then when you do " a[5] = {4,4,4,4,4,4}+b[5] = {4,4,4,4,4,4};"Code:int c[255] = {0};
the result put into c can be begin from 0,
like c[0] = a[4]+b[4],c[1] = a[3]+b[3]...
Last edited by Jesius; 11-28-2010 at 03:34 AM.
Are you sure you're not tripping over that old C problem where the number of elements does not equal the numbers of the elements?
Array elements always number from 0, not from 1, so a[5] has elements numbered 0 ,1 ,2, 3, 4
There is no element #5... but there is The 5th Element