Advertisement
halexandru11

atestat_13.cpp

Nov 25th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     ifstream fin("tablou.in");
  8.     ofstream fout("tablou.out");
  9.  
  10.     // citesc datele de intrare
  11.     unsigned int n;
  12.     unsigned int a[101];
  13.     fin >> n;
  14.     for(int i = 0; i < n; ++i) {
  15.         fin >> a[i];
  16.     }
  17.  
  18.     // sortez vectorul in ordine crescatoare
  19.     for(int i = 0; i < n-1; ++i) {
  20.         for(int j = i+1; j < n; ++j) {
  21.             if(a[i] > a[j]) {
  22.                 int aux = a[i];
  23.                 a[i] = a[j];
  24.                 a[j] = aux;
  25.             }
  26.         }
  27.     }
  28.  
  29.     // afisez elementele vectorului sortate crescator
  30.     // in timpul parcurgerii retin cel mai mare si cel mai mic numar par din vector
  31.     unsigned int mini = 10000000, maxi = 0;
  32.     for(int i = 0; i < n; ++i) {
  33.         fout << a[i] << " ";
  34.         if(a[i] % 2 == 0) {
  35.             maxi = (a[i] > maxi ? a[i] : maxi);
  36.             mini = (a[i] < mini ? a[i] : mini);
  37.         }
  38.     }
  39.     fout << "\n";
  40.     fout << maxi << " " << mini;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement