Advertisement
programusy

kot niewiadomo kogog

Feb 2nd, 2023 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void sito(bool *tab, unsigned int n)
  6. {
  7. for (int i=2; i*i<=n; i++)
  8. {
  9. if(!tab[i])
  10. for (int j = i*i ; j<=n; j+=i)
  11. tab[j] = 1;
  12. }
  13. }
  14.  
  15. int main()
  16. {
  17. int n;
  18. bool *tab;
  19. n = 100;
  20.  
  21. tab = new bool [n+1];
  22.  
  23. for(int i=2; i<=n; i++)
  24. tab[i] = 0;
  25.  
  26. sito(tab, n);
  27.  
  28. cout<<"Liczby pierwsze to: "<<endl;
  29.  
  30. for(int i=2;i<=n;i++)
  31. if(!tab[i])
  32. cout<<i<<" ";
  33. cout<<endl;
  34. int a;
  35. cout<<"podaj liczbe do sprawdzenia"<<endl;
  36. cin>>a;
  37.  
  38.  
  39.  
  40. int u = sizeof(tab) / sizeof(*tab);
  41.  
  42. bool istnieje = find(tab, tab + u, a) != tab + u;
  43. if (istnieje) {
  44. cout << "Liczba jest w tablicy"<<endl;
  45. } else {
  46. cout << "Liczby nie ma w tablicy"<<endl;
  47. }
  48.  
  49. return 0;
  50.  
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement