forked from malep2007/C-Programming-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQUESTION 4
More file actions
40 lines (36 loc) · 826 Bytes
/
QUESTION 4
File metadata and controls
40 lines (36 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
4a)
#include <stdio.h>
#include <stdlib.h>
int j, n;
int main()
{
int *addarrays(int n, int x[], int y[], int z[])
int i;
for (i=0; i<n; i++)
{
z[i] = x[i] + y[i];
}
return z;
}
4b)
#include <stdio.h>
int *addarrays(int array1[], int array2[], int SIZE);
main()
{
int array1[] = {2,5,3,22,6};
int array2[] = {13,143,11,10,121};
int *array3 = addarrays(array1, array2, 5);
for(int i=0;i<5;i++)
{
printf("%d ", array3[i]);
}
}
int *addarrays(int array1[], int array2[], int length)
{
int *destination_array = malloc(length * sizeof(int));
for(int i=0;i<length;i++)
{
destination_array[i] = array1[i] + array2[i];
}
return destination_array;
}