Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* Program to sum the integers of an arbitrary size array*/
- int array_sum (int a[], int n)
- {
- int x;
- int answer = 0;
- for (x = 0; x < n; ++x )
- answer = answer + a[x];
- return (answer);
- }
- int main (void)
- {
- int n = 5;
- int i;
- int a[n];
- printf ("Please enter the elements of your array, one by one\n");
- for (i = 0; i < n; i++)
- scanf ("%i", &a[i]);
- printf ("The sum of all elements of your array is: %i\n", array_sum (a, n));
- }
Add Comment
Please, Sign In to add comment