# array question

• 02-18-2002
KAchE
array question
Hi, I got a question. If i have an array of five cells, each storing a single digit number, and another array of the same, how can i add both arrays so that the sum is stored in an array of six cells? If there is no carry, then sum[0] must hold a zero.

eg.
integer1={4,5,0,7,1}
integer2={9,2,9,8,7}
sum={1,3,8,0,5,8}
• 02-18-2002
Salem
Code:

```integer1[6]={0,4,5,0,7,1} integer2[6]={0,9,2,9,8,7} sum[6]={1,3,8,0,5,8}```
Consider what integer1[i] + intege2[i] is

Then consider what it means if that result is >= 10

Then think about a for loop
• 02-18-2002
Unregistered
If you just want to sum 2 numbers, an array is an awkward way to do it. You would have to walk through both arrays in reverse order, and keep a carry. Let us know if you need more info.
• 02-18-2002
Xterria
Code:

```#include "stdio.h" int main() { int var=0; int integer1[6]={0,4,5,0,7,1}; //make element 5, arrays start with 0 int integer2[6]={0,9,2,9,8,7}; int sum[6] = {0,0,0,0,0,0}; printf("The sum array is: "); while(var<6) {     sum[var] = integer1[var]+integer2[var];     printf("%d ",sum[var]);     var++; } return 0; }```
• 02-18-2002
KAchE
Thanks for all the help guys, i got it.