Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void dodaj(int tab[], int dlugosc)
- {
- for(int i=0; i<dlugosc; i++)
- {
- cout << "Podaj element " << i << ": ";
- cin >> tab[i];
- }
- }
- void wyswietl(int tab[], int dlugosc)
- {
- for(int i=0; i<dlugosc; i++)
- cout << "Element " << i << ": " << tab[i] << endl;
- }
- int NajczestszaWartosc(int tab[], int dlugosc)
- {
- int najwiecej=0, wynik;
- for(int x=0; x<dlugosc; x++)
- {
- int licznik=0;
- for(int y=x; y<dlugosc; y++)
- {
- if(tab[x]==tab[y])
- {
- licznik++;
- if(licznik>najwiecej)
- {
- najwiecej=licznik;
- wynik=tab[x];
- }
- }
- }
- }
- return wynik;
- }
- int main()
- {
- cout << "Ile elementow ma posiadac tablica?: ";
- int ile;
- cin >> ile;
- int tab[ile];
- dodaj(tab, ile);
- wyswietl(tab, ile);
- cout << NajczestszaWartosc(tab,ile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement