Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int main()
- {
- const int N = 100000;
- int Z [ N ], i, j, L, W, maxL, maxW;
- // Generujemy zawartość Z [ ]
- srand((unsigned)time(NULL));
- for(i = 0; i < N; i++) Z [ i ] = 50 + rand() % 41;
- // Wyszukujemy najczęstszą wartość
- maxL = 0;
- for(i = 0; i < N; i++)
- {
- W = Z [ i ]; L = 0;
- for(j = 0; j < N; j++) if(Z [ j ] == W) L++;
- if(L > maxL)
- {
- maxL = L; maxW = W;
- }
- }
- // Wypisujemy tablicę
- // for(i = 0; i < N; i++)
- // if(Z [ i ] == maxW) cout << " >" << setw(2) << Z [ i ];
- // else cout << setw(4) << Z [ i ];
- // Wypisujemy najczęstszy element oraz liczbę wystąpień
- cout << endl << maxW << ": " << maxL << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement