Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<vector>
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. template<class Type>
  7. Type Sum(vector<Type> &A) {
  8.     Type S = 0;
  9.     for (auto a : A) {
  10.         S += a;
  11.     }
  12.     return S;
  13. }
  14. template<class Type>
  15. Type Max(vector<Type> &A) {
  16.     Type S = A[0];
  17.     for (int i = 1; i < A.size();i++) {
  18.         if(A[i]>S)
  19.             S=A[i];
  20.     }
  21.     return S;
  22. }
  23.  
  24. int main()
  25. {
  26.     vector<int> V = { 1,2,3,4,5,6,7,8,9 };
  27.     vector<double> VD{ 1.1,2.2,3.3,4.4,5.5 };
  28.     cout << Sum(V) << endl;
  29.     cout << Sum(VD) << endl;
  30.     cout << Max(V) << endl;
  31.     system("pause");
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement