Advertisement
rizky_herucakra

sum int

Dec 7th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <size_t sz>
  6. int sum (const int(&a)[sz]){
  7.     int result = 0;
  8.     for (size_t i = 0; i < sz; ++i){
  9.         result += a[i];
  10.     }
  11.     return result;
  12. }
  13.  
  14. int main()
  15. {
  16.     int arr [5] = {1,2,3,4,5};
  17.     int sum_result  = sum(arr);
  18.     cout << "the sum is = " << sum_result;
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement