Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void sito(bool *tab, unsigned int n)
- {
- for (int i=2; i*i<=n; i++)
- {
- if(!tab[i])
- for (int j = i*i ; j<=n; j+=i)
- tab[j] = 1;
- }
- }
- int main()
- {
- int n;
- bool *tab;
- n = 100;
- tab = new bool [n+1];
- for(int i=2; i<=n; i++)
- tab[i] = 0;
- sito(tab, n);
- cout<<"Liczby pierwsze to: "<<endl;
- for(int i=2;i<=n;i++)
- if(!tab[i])
- cout<<i<<" ";
- cout<<endl;
- int a;
- cout<<"podaj liczbe do sprawdzenia"<<endl;
- cin>>a;
- int u = sizeof(tab) / sizeof(*tab);
- bool istnieje = find(tab, tab + u, a) != tab + u;
- if (istnieje) {
- cout << "Liczba jest w tablicy"<<endl;
- } else {
- cout << "Liczby nie ma w tablicy"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement