Advertisement
pcwizz

this

Oct 17th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int total (int arr_len, int *arr)
  6. {
  7.     if ( arr_len == 0 )
  8.         return 0;
  9.     return *arr + total(--arr_len, arr + 1);
  10. }
  11.  
  12. int main ()
  13. {
  14.     int arr[] = {1,2,3,4,5,6,7,8,9};
  15.     int arr_len = sizeof(arr) / sizeof(arr[0]);
  16.     cout << total(arr_len, arr) << endl;
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement