SHARE
TWEET

Untitled

LazySenpai Jan 18th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Napisz program generujacy ciag liczb pierwszych od 0 do n metoda sita Eratostanesa.
  2. #include <iostream>
  3.  
  4.  
  5. using std::cout;
  6. using std::cin;
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     cout << "n = ";
  12.     cin >> n;
  13.     int *t = new int[n];
  14.    
  15.     for(int x=0; x<n-1; x++)
  16.     {
  17.         t[x]=x+2;
  18.     } //przypisanie wartosci do elementow
  19.  
  20.     for(int x=0; x<n-1; x++)
  21.     {
  22.         for(int y=2; y<n-1; y++)
  23.         {
  24.             if(t[x]%y==0&&t[x]!=y)
  25.                 t[x]=0;
  26.         }
  27.     } //wyszukiwanie liczb bez podzielnikow
  28.  
  29.     cout << "Prime numbers :\n  ";
  30.  
  31.     for(int x=0; x<n-1; x++)
  32.     {
  33.         if(t[x]>0)
  34.             cout << t[x] << " ";
  35.     } //wyswietlanie
  36.    
  37.     delete []t;
  38.     cin.get();
  39.     cin.get();
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top