Advertisement
informaticage

max min sum ez

Nov 18th, 2021
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.   int N;
  8.   cout << "Inserire N: ";
  9.   cin >> N;
  10.  
  11.   int massimo = numeric_limits<int>::min();
  12.   int minimo = numeric_limits<int>::max();
  13.   int somma = 0;
  14.  
  15.   for(int i = 0; i < N; i++) {
  16.     int temp;
  17.     cin >> temp;
  18.  
  19.     somma = somma + temp;
  20.     if(temp >  massimo) massimo = temp;
  21.     if(temp < minimo) minimo = temp;
  22.   }
  23.  
  24.   cout << "Massimo: " << massimo << endl;
  25.   cout << "Minimo: " << minimo << endl;
  26.   cout << "Somma: " << somma << endl;
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement