Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Napisz program generujacy ciag liczb pierwszych od 0 do n metoda sita Eratostanesa.
- #include <iostream>
- using std::cout;
- using std::cin;
- int main()
- {
- int n;
- cout << "n = ";
- cin >> n;
- int *t = new int[n];
- for(int x=0; x<n-1; x++)
- {
- t[x]=x+2;
- } //przypisanie wartosci do elementow
- for(int x=0; x<n-1; x++)
- {
- for(int y=2; y<n-1; y++)
- {
- if(t[x]%y==0&&t[x]!=y)
- t[x]=0;
- }
- } //wyszukiwanie liczb bez podzielnikow
- cout << "Prime numbers :\n ";
- for(int x=0; x<n-1; x++)
- {
- if(t[x]>0)
- cout << t[x] << " ";
- } //wyswietlanie
- delete []t;
- cin.get();
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement