Advertisement
sellmmaahh

tut5-zad6

Jul 22nd, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <deque>
  5.  
  6. template <typename Tip>
  7. auto SumaBloka (Tip It1, Tip It2) -> decltype(*It1+*It1) {
  8.     decltype (*It1+*It1) suma{0};
  9.     while (It1!=It2)
  10.             suma+=*It1++;
  11.     return suma;
  12. }
  13.  
  14. int main () {
  15.     std::cout<<"Unesite elemente deka (0 za kraj): "<<std::endl;
  16.     std::deque<int> d;
  17.     int n;
  18.     while (std::cin>>n, n!=0) d.push_back(n);
  19.     std::cout<<"Suma elemenata: "<<SumaBloka(d.begin(),d.end());
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement