Advertisement
monyca98

afisarea celor mai mari term pari preced de strict 3 imp

Mar 2nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. void afisare()
  5. {
  6.     ifstream fin("bac.txt");
  7.     int count = 0;
  8.     int max1 = -1,max2=-1;
  9.     int a;
  10.     while (fin>>a && count!=4)
  11.     {
  12.         if (a% 2 != 0)
  13.             count++;
  14.         if (count == 3 && a % 2 == 0)
  15.         {
  16.            
  17.             if (a > max1)
  18.             {
  19.                 if (max1 > max2)
  20.                     max2 = max1;
  21.                 max1 = a;
  22.             }
  23.             else
  24.                 if(a>max2)
  25.                     max2 = a;
  26.         }
  27.        
  28.     }
  29.     if (max1 == -1 || max2 == -1)
  30.         cout << "nu exista";
  31.     else
  32.     {
  33.         if (max1 < max2)
  34.             cout << max1 << " " << max2;
  35.         else
  36.             cout << max2 << " " << max1;
  37.     }
  38. }
  39. int main()
  40. {
  41.  
  42.     afisare();
  43.     cout << endl << endl;
  44.     system("pause");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement