Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void sum_array(int array[], int len, int* sum) {
  5.     int* p = array;
  6.     *sum = 0;
  7.  
  8.     while(len--) {
  9.         *sum += *p;
  10.         p++;
  11.     }
  12. }
  13.  
  14. int main() {
  15.     int array[] = {2, 2, 2, 2, 2};
  16.     int len = 5, sum;
  17.  
  18.     sum_array(array, len, &sum);
  19.  
  20.     printf("sum: %d", sum);
  21.  
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement