Doggy1337 Napisano Maj 26, 2021 Zgłoś Napisano Maj 26, 2021 Cieplutko proszę o pomoc, ponieważ muszę odesłać ten projekt do jutra. W skrócie: Program poszukuje lidera w wylosowanej tablicy. Tutaj podsyłam mój kod, niestety pojawia się błąd w linijce 44. Serdecznie proszę o rozwiązanie mojego problemu wykorzystując funkcje, które ja użyłem, bo tylko takie przerabiałem w szkole. ``` #include <iostream> #include <algorithm> #include <cstdlib> #include <ctime> using namespace std; const int N=20; int SzukajLidera(int A[]) { int i, kandydat, ile=0; sort(A,A+N); kandydat=A[N/2]; for (i=0;i<N;i++) if (A[i]==kandydat) ile++; if (ile>N/2) return kandydat; else return -1; } void Losuj(int A[]) { int x=rand()%100; for (int i=0;i<N;i++) if (rand()%2==0) A[i]=rand()%100; else A[i]=x; } void Wypisz(int A[]) { for (int i=0;i<N;i++) cout<<A[i]<<" "; cout<<endl; } int main() { int A[N]; srand(time(NULL)); Losuj(A); Wypisz(A); } int kandydat; int SzukajLidera (int A[kandydat]) { return -1*kandydat;} return 0; ``` Cytuj
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.