Advertisement
Guest User

Exercise

a guest
Aug 30th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /*Use a copy function from exercise 2 to copy the third through fifth elements of a seven-element array into a three-element array.
  2. The function itself need not be altered; just choose the right actual arguments.
  3. (The actual arguments need not be an array name and array size. They only have to be the
  4. address of an array element and a number of elements to be processed.)
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. #define SIZE 7
  10.  
  11. void copy_arr(double source[], double target[], int element);
  12.  
  13. int main(void)
  14. {
  15.     double source[SIZE] = { 2.4, 5.6, 7.8, 4.7, 2.6, 8.4, 3.6 };
  16.  
  17.     double target[SIZE - 4];
  18.     int i;
  19.    
  20.     for (i = 2; i < 5; ++i) {
  21.         copy_arr(source, target, i);
  22.     }
  23.  
  24.     return 0;
  25. }
  26.  
  27. void copy_arr(double source[], double target[], int element)
  28. {
  29.     int tar_element = element - 2;
  30.  
  31.     target[tar_element] = source[element];
  32.  
  33.     printf("%.1lf ", target[tar_element]);
  34.  
  35.     putchar('\n');
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement