数组和.c 265 B

123456789101112131415161718
  1. #include <stdio.h>
  2. int sum(int n, int *arr) {
  3. int sum = 0, i;
  4. for(i = 0; i < n; i++) sum += *(arr + i);
  5. return sum;
  6. }
  7. int main() {
  8. int n,i;
  9. scanf("%d",&n);
  10. int arr[n];
  11. for (i = 0; i < n; i++) scanf("%d",&arr[i]);
  12. printf("%d",sum(n, arr));
  13. return 0;
  14. }