Advertisement
dllbridge

Untitled

Apr 16th, 2025
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include  <iostream>
  5. #include      <list>
  6. #include     <ctime>
  7. #include   <iomanip>
  8. #include   <cstdlib>
  9. using namespace std;
  10.  
  11.  
  12. void monitor(list<int> &r);
  13.  
  14. //////////////////////////////////////////////////////////////  27, 195
  15. int main()                                                  //  
  16. {
  17.  
  18.     srand(time(0));
  19.  
  20.     list<int> L_1;
  21.    
  22.     int n = 0;
  23.  
  24.    
  25.     for(int i = 0; i < 20; i++)
  26.     {
  27.  
  28.        
  29.         n = rand()%200;
  30.        
  31.         L_1.push_back(n);
  32.        
  33.     }
  34.    
  35.     monitor(L_1);
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. ///////////////////////////////////////////////////////////////
  44. void monitor(list<int> &r)
  45. {
  46.    
  47.      int   n_min = 0,
  48.            n_Max = 0,  
  49.            n        ;
  50.  
  51.     list<int>::iterator it;
  52.    
  53.     it = r.begin();
  54.  
  55.     for(int i = 0; i < 20; i++)
  56.     {
  57.         n = *it;
  58.            
  59.         cout << setw(3) <<  i << ") n = " << setw(3) << n << endl;  
  60.        
  61.         if( i == 0 ) n_min = n_Max = n;
  62.         else
  63.         {
  64.             if(n > n_Max) n_Max = n;
  65.             if(n < n_min) n_min = n;           
  66.         }
  67.        
  68.         it ++;
  69.     }            
  70.     cout << " - - -  - - - -  - - - \n";
  71.     cout << "n_Max = " << n_Max << endl;
  72.     cout << "n_min = " << n_min << endl;       
  73. }
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement