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
38 lines (33 loc) · 707 Bytes
/
QUESTION 4
File metadata and controls
38 lines (33 loc) · 707 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
/* Rwego Ndahiro David
Reg No: 16/X/2364/PS*/
//ANSWERS:
//i)
void addarrays(int array1[], int array2[], int summation_array[], int SIZE)
{
for(int i=0;i<SIZE;i++)
{
//ii)
summation_array[i] = array1[i] + array2[i];
}
}
//iii)
#include <stdio.h>
int *addarrays(int array1[], int array2[], int SIZE);
main(){
//iv)
int array1[] = {1,2,3,4,5};
int array2[] = {6,7,8,9,10};
int *array3 = addarrays(array1, array2, 5);
for(int i=0;i<5;i++) {
//v)
printf("%d \n", array3[i]);
}
}
int *addarrays(int array1[], int array2[], int length){
int *destination_array = malloc(length * sizeof(int));
for(int i=0;i<length;i++){
//vi)
destination_array[i] = array1[i] + array2[i];
}
return destination_array;
}