Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main() {
- ifstream fin("tablou.in");
- ofstream fout("tablou.out");
- // citesc datele de intrare
- unsigned int n;
- unsigned int a[101];
- fin >> n;
- for(int i = 0; i < n; ++i) {
- fin >> a[i];
- }
- // sortez vectorul in ordine crescatoare
- for(int i = 0; i < n-1; ++i) {
- for(int j = i+1; j < n; ++j) {
- if(a[i] > a[j]) {
- int aux = a[i];
- a[i] = a[j];
- a[j] = aux;
- }
- }
- }
- // afisez elementele vectorului sortate crescator
- // in timpul parcurgerii retin cel mai mare si cel mai mic numar par din vector
- unsigned int mini = 10000000, maxi = 0;
- for(int i = 0; i < n; ++i) {
- fout << a[i] << " ";
- if(a[i] % 2 == 0) {
- maxi = (a[i] > maxi ? a[i] : maxi);
- mini = (a[i] < mini ? a[i] : mini);
- }
- }
- fout << "\n";
- fout << maxi << " " << mini;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement