Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <sstream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- ifstream input{"input_8.2.txt"};
- vector<int> valori_tot = {};
- for (string line; getline(input, line);){
- istringstream sstr{line};
- for (string misure; getline(sstr, misure, ',');){
- int misura = stoi(misure);
- valori_tot.push_back(misura);
- }
- }
- int sum = 0;
- for (int elemento : valori_tot){
- sum += elemento;
- }
- float media = 0.0;
- media = float(sum) / valori_tot.size();
- cout <<"Media: "<< media << endl;
- int max_value = *max_element(valori_tot.begin(), valori_tot.end());
- int min_value = *min_element(valori_tot.begin(), valori_tot.end());
- cout << "Valore massimo: " << max_value << endl;
- cout << "Valore minimo: " << min_value << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement