DMG

Drugi najveci clan niza

DMG
Mar 22nd, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. /* Napisati program koji pronalazi drugi najveci clan niza */
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, a[50], t, i, max;
  8.     cin >> n;
  9.     for (int i=0; i<n; i++)
  10.     cin >> a[i];
  11.     for (int i=n-2; i>=0; i--)
  12.     for (int j=0; j<=i; j++)
  13.         if (a[j] < a[j+1])
  14.         {
  15.                  t = a[j];
  16.                  a[j] = a[j+1];
  17.                  a[j+1] = t;
  18.         }
  19.     i = 1;  
  20.     max = a[0];  
  21.     while (i<n)
  22.     {
  23.           if (a[i]==a[i-1])
  24.           i = i + 1;
  25.           else
  26.           {
  27.               max = a[i];
  28.               i = n;
  29.           }
  30.     }
  31.     if (max == a[0])
  32.     cout << "Niz je konstantan!" << endl;
  33.     else
  34.     cout << max << endl;
  35.     system ("PAUSE");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment