Guest User

Untitled

a guest
Nov 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* Program to sum the integers of an arbitrary size array*/
  4.  
  5. int array_sum (int a[], int n)
  6. {
  7. int x;
  8. int answer = 0;
  9.  
  10. for (x = 0; x < n; ++x )
  11. answer = answer + a[x];
  12.  
  13. return (answer);
  14.  
  15. }
  16.  
  17.  
  18. int main (void)
  19. {
  20.  
  21. int n = 5;
  22. int i;
  23. int a[n];
  24.  
  25. printf ("Please enter the elements of your array, one by one\n");
  26.  
  27. for (i = 0; i < n; i++)
  28. scanf ("%i", &a[i]);
  29.  
  30. printf ("The sum of all elements of your array is: %i\n", array_sum (a, n));
  31. }
Add Comment
Please, Sign In to add comment