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
68 lines (47 loc) · 1.34 KB
/
Copy pathQuestion 4
File metadata and controls
68 lines (47 loc) · 1.34 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Write a function named addarrays() that accepts two arrays that are the same size.
The function should add each element in the arrays together and place the values in a third array.
Function that accepts two arrays of same size
and adds them together. The result is then
stored in third array
*/
#include <stdio.h>
void addArrays(int firstArray[], int secondArray[], int arrayAddResults[], int array_size);
/*The two Arrays of the same size are firstArray and secondArray*/
/*Result of addition of the arrays is arrayAddResults*/
/*array_size is the size of the array*/
main(){
//Main function
}
void addArrays(int firstArray[], int secondArray[], int arrayAddResults[], int array_size){
int x=0;
while(x<array_size){
arrayAddResults[x]=firstArray[x]+secondArray[x];
x=x+1;
getch();
}
}
/*
4(b)
*/
#include <stdio.h>
int *addArrays(int myArray1[], int myArray2[], int arraySize);
main(){
int myArray1[]={1,2,3,4,5,6,7,8,9,10};
int myArray2[]={11,12,13,14,15,16,17,18,19,20};
int *myArrayResult=addArrays(myArray1, myArray2,10);
int i=1;
while(u<10){
printf("%s\n",myArrayResult[i]);
i=i+1;
}
}
int *addArrays(int myArray1[], int myArray2[], int arraySize){
int *destinationArray=malloc(arraySize*sizeof(int));
int i=1;
while(i<arraySize){
destinationArray[i]=myArray1[i]+myArray2[i];
i=i+1;
}
return destinationArray;
}