Skocz do zawartości

Recommended Posts

Napisano

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;
 

```

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...