Advertisement
STANAANDREY

learning poash temp

Mar 8th, 2025
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #if defined(_MSC_VER)
  2. #include <__msvc_all_public_headers.hpp>
  3. #elif defined(__GNUC__)
  4. #include <bits/stdc++.h>
  5. #else
  6. #error "Unsupported compiler"
  7. #endif
  8. using namespace std;
  9.  
  10. template <typename T, size_t size>
  11. T sum(T(&arr)[size]) {
  12.     T s = 0;
  13.     for (size_t i = 0; i < size; i++) {
  14.         s += arr[i];
  15.     }
  16.     return s;
  17. }
  18.  
  19. int main() {
  20.     int arr[] = { 1, 2, 3, 4, 5 };
  21.     cout << sum(arr) << endl;
  22.     return 0;
  23. }
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement