1
0

arf.c 795 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* arf.c -- array functions */
  2. #include <stdio.h>
  3. #define SIZE 5
  4. void show_array(const double ar[], int n);
  5. void mult_array(double ar[], int n, double mult);
  6. int main(void)
  7. {
  8. double dip[SIZE] = {20.0, 17.66, 8.2, 15.3, 22.22};
  9. printf("The original dip array:\n");
  10. show_array(dip, SIZE);
  11. mult_array(dip, SIZE, 2.5);
  12. printf("The dip array after calling mult_array():\n");
  13. show_array(dip, SIZE);
  14. return 0;
  15. }
  16. /* displays array contents */
  17. void show_array(const double ar[], int n)
  18. {
  19. int i;
  20. for (i = 0; i < n; i++)
  21. printf("%8.3f ", ar[i]);
  22. putchar('\n');
  23. }
  24. /* multiplies each array member by the same multiplier */
  25. void mult_array(double ar[], int n, double mult)
  26. {
  27. int i;
  28. for (i = 0; i < n; i++)
  29. ar[i] *= mult;
  30. }