avukas

Peti tut, 6.zad

Mar 28th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3.  
  4. template<typename tip, typename TipS>
  5.  
  6. auto SumaBloka(tip p1, tip p2, TipS suma) -> decltype(*p1 + *p2)
  7. {
  8.  
  9.     while (p1 != p2)
  10.     {
  11.         suma=suma+*p1;
  12.  
  13.         p1++;
  14.  
  15.     }
  16.     return suma;
  17. }
  18.  
  19. int main()
  20. {
  21.     std::deque<int> d;
  22.     int n;
  23.     std::cout<<"Unesi dimenziju bloka:\n";
  24.     std::cin>>n;
  25.     std::cout<<"\nUnesi elemente bloka:\n";
  26.     for (int i(0); i<n; i++)
  27.     {
  28.         int pom;
  29.         std::cin>>pom;
  30.        d.push_back(pom);
  31.     }
  32.  
  33.  
  34.     int suma(0);
  35.  
  36.     int s = SumaBloka(d.begin(), d.end(), suma);
  37.     std::cout<<"\nSuma bloka je: "<<s<<std::endl;
  38.  
  39.  
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment