Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int SequentialSearch(int tab[],int lenght,int s,int &p);
  9.  
  10. int main()
  11. {
  12. int *tab, lenght, s,p=0,locznieporownan=0, pff=0;
  13. float wynik;
  14. srand(time(NULL));
  15. cout<<"Lenght: ";
  16. cin>>lenght;
  17. tab = new int[lenght];
  18. cout<<"Szukamy: ";
  19. cin>>s;
  20. cout<<"Wprowadz ilosc tablic: ";
  21. cin>>pff;
  22.  
  23. for(int xd=0;xd<pff;xd++)
  24. {
  25. cout<<endl<<endl<<SequentialSearch(tab,lenght,s,p);
  26. locznieporownan=locznieporownan+p;
  27. cout<<"\n\nIlosc porownan to: "<<p<<endl<<endl<<"----------------------"<<endl;
  28. }
  29. cout<<endl<<endl<<(locznieporownan);
  30. cout<<"/ "<<pff;
  31. wynik=(float)((locznieporownan)/pff);
  32. cout<<endl<<endl<<wynik;
  33. return 0;
  34. }
  35. int SequentialSearch(int tab[],int lenght,int s,int &p)
  36. {
  37. p=0;
  38. for(int i = 0; i < lenght; i++)
  39. {tab[i]=rand()%lenght;cout<<tab[i]<<" ";}
  40. cout<<endl;
  41. for(int i=0; i<(lenght); i++)
  42. {
  43. p++;
  44. if(tab[i]==s) {return i+1;}
  45. else{}
  46. }
  47. return -1;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement