Hi all..it's me again...
Code:
// Write a function named sumarrays() that accepts two arrays as arguments, totals all values in both arrays, and returns the total to the calling program. Use the function created in exercise 7 in a simple program.
#include <stdio.h>
#define MAX 5
int array_1[MAX], array_2[MAX], count;
int sumarrays(int array_1[], int array_2[], int length);
int main()
{
int a;
for(count = 0; count < MAX; count++)
{
printf("Enter an integer value (array_1): ");
scanf("%d", &array_1[count]);
}
for(count = 0; count < MAX; count++)
{
printf("Enter an integer value (array_2): ");
scanf("%d", &array_2[count]);
}
int answer;
answer = sumarrays(array_1, array_2, MAX);
printf("Total of both arrays = %d\n", answer);
return 0;
}
int sumarrays(int num_array_1[], int num_array_2[], int length)
{
int a, total;
total = 0;
count = 0;
for(count = 0; count < length; count++)
{
total += num_array_1[count];
}
for(count = 0; count < length; count++)
{
total += num_array_2[count];
}
return total;
}
please explain, how sum is being added with this line:
Code:
answer = sumarrays(array_1, array_2, MAX);
Thank you!!!
I wrote this code, it was a Q&A out of a Sam's Teach yourself C programming in 24 hours...