Advertisement
horselurrver

Sum up

Aug 5th, 2016
2,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void sum(int array1[], int array2[], int array3[], int size);
  4.  
  5. int main(void){
  6.     const int SIZE=4;
  7.     int array1[]={2,4,5,8};
  8.     int array2[]={1,0,4,6};
  9.     int array3[SIZE];
  10.     int x;
  11.     sum(array1, array2, array3, SIZE);
  12.    
  13.     for (x=0; x<SIZE; x++){
  14.         printf("%4d", array3[x]);
  15.     }
  16.     printf("\n");
  17.     return 0;
  18. }
  19.  
  20. void sum(int array1[], int array2[], int array3[], int size){
  21.     int i;
  22.     int *ptr1, *ptr2, *ptr3;
  23.     ptr1=array1;
  24.     ptr2=array2;
  25.     ptr3=array3;
  26.     for(i=0; i<size; i++){
  27.         *ptr3=*ptr1+*ptr2;
  28.         ptr1++;
  29.         ptr2++;
  30.         ptr3++;
  31.     }
  32.    
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement