Sum the same index elements of two arrays and store the result in different array.
For example:
If the input arrays are
1 2 3 4 5
6 7 8 9 10
then the resultant array is
7 9 11 13 15
Implementation:
For example:
If the input arrays are
1 2 3 4 5
6 7 8 9 10
then the resultant array is
7 9 11 13 15
Implementation:
#include <stdio.h> int main(void) { int *a,*b,*sum,i,n; /* Get the number of elements of the array */ scanf("%d",&n); /* allocate the memory for array a and array b */ a=(int*)malloc(sizeof(int)*n); b=(int*)malloc(sizeof(int)*n); /* allocate the memory for array sum and initialize their values to zero */ sum=(int*)calloc(n,sizeof(int)); /* Get the elements of the array a */ for(i=0;i<n;i++) scanf("%d",(a+i)); /* Get the elements of the array b */ for(i=0;i<n;i++) scanf("%d",(b+i)); /* Sum the same indexed array a and array b & store the result in array sum */ for(i=0;i<n;i++) *(sum+i)=*(a+i)+*(b+i); /* print the array sum , which has the sum of array a and array b */ for(i=0;i<n;i++) printf("%d ",*(sum+i)); return 0; }