Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int SequentialSearch(int tab[],int lenght,int s,int &p);
- int main()
- {
- int *tab, lenght, s,p=0,locznieporownan=0, pff=0;
- float wynik;
- srand(time(NULL));
- cout<<"Lenght: ";
- cin>>lenght;
- tab = new int[lenght];
- cout<<"Szukamy: ";
- cin>>s;
- cout<<"Wprowadz ilosc tablic: ";
- cin>>pff;
- for(int xd=0;xd<pff;xd++)
- {
- cout<<endl<<endl<<SequentialSearch(tab,lenght,s,p);
- locznieporownan=locznieporownan+p;
- cout<<"\n\nIlosc porownan to: "<<p<<endl<<endl<<"----------------------"<<endl;
- }
- cout<<endl<<endl<<(locznieporownan);
- cout<<"/ "<<pff;
- wynik=(float)((locznieporownan)/pff);
- cout<<endl<<endl<<wynik;
- return 0;
- }
- int SequentialSearch(int tab[],int lenght,int s,int &p)
- {
- p=0;
- for(int i = 0; i < lenght; i++)
- {tab[i]=rand()%lenght;cout<<tab[i]<<" ";}
- cout<<endl;
- for(int i=0; i<(lenght); i++)
- {
- p++;
- if(tab[i]==s) {return i+1;}
- else{}
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement