Created
October 15, 2012 13:37
-
-
Save HappyCerberus/3892501 to your computer and use it in GitHub Desktop.
Istream and ostream iterator demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iterator> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int main() | |
{ | |
istream_iterator<double> in(cin); | |
istream_iterator<double> eof; | |
ostream_iterator<double> out(cout," "); | |
vector<double> pole; | |
copy(in,eof,back_inserter(pole)); | |
double suma = 0; | |
for (size_t i = 0; i < pole.size(); i++) | |
{ | |
suma += pole[i]; | |
} | |
cout << "Suma cisel : " << endl; | |
copy(pole.begin(),pole.end(),out); | |
cout << endl << "je : " << suma << endl; | |
cout << "Prumer je : " << suma / pole.size() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment