D
Darklight
Question:
Write a function named sumarrays() that accepts two arrays that are the same
size. The function should add each element in the array together and place
the values in the thrid array.
Which answer is the better practice;
/*EX9.C*/
#include<stdio.h>
#define MAX 5
int array2[MAX] = {1,2,3,4,5};
int array3[MAX] = {6,7,8,9,10};
int sumarray(int array2[], int array3[]);
int main(void)
{
sumarray(array2,array3);
return 0;
}
int sumarray(int array2[], int array3[])
{
int ctr;
int total[MAX];
for(ctr = 0; ctr < MAX; ctr++)
{
total[ctr] = array2[ctr] + array3[ctr];
printf("Total %d\n",total[ctr]);
}
return total[count];
}
____________________________________________
/* EX9-1.C*/
#include<stdio.h>
#define SIZE 5
void sumarray(int [], int []);
int main(void)
{
int a[SIZE] = {1,2,3,4,5};
int b[SIZE] = {6,7,8,9,10};
sumarray(a,b);
return 0;
}
void sumarray(int first[], int second[])
{
int total[SIZE];
int ctr;
for(ctr = 0; ctr < SIZE; ctr++)
{
total[ctr] = first[ctr] + second[ctr];
printf("Total %d\n",total[ctr]);
}
}
Write a function named sumarrays() that accepts two arrays that are the same
size. The function should add each element in the array together and place
the values in the thrid array.
Which answer is the better practice;
/*EX9.C*/
#include<stdio.h>
#define MAX 5
int array2[MAX] = {1,2,3,4,5};
int array3[MAX] = {6,7,8,9,10};
int sumarray(int array2[], int array3[]);
int main(void)
{
sumarray(array2,array3);
return 0;
}
int sumarray(int array2[], int array3[])
{
int ctr;
int total[MAX];
for(ctr = 0; ctr < MAX; ctr++)
{
total[ctr] = array2[ctr] + array3[ctr];
printf("Total %d\n",total[ctr]);
}
return total[count];
}
____________________________________________
/* EX9-1.C*/
#include<stdio.h>
#define SIZE 5
void sumarray(int [], int []);
int main(void)
{
int a[SIZE] = {1,2,3,4,5};
int b[SIZE] = {6,7,8,9,10};
sumarray(a,b);
return 0;
}
void sumarray(int first[], int second[])
{
int total[SIZE];
int ctr;
for(ctr = 0; ctr < SIZE; ctr++)
{
total[ctr] = first[ctr] + second[ctr];
printf("Total %d\n",total[ctr]);
}
}