Advertisement
MeehoweCK

Untitled

Dec 5th, 2020
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 50;
  6.  
  7. bool czy_pierwsza(int n)
  8. {
  9.     for(int i = 2; i * i <= n; ++i)
  10.         if(n % i == 0)
  11.             return false;
  12.     return true;
  13. }
  14.  
  15. int nastepna_pierwsza(int n)
  16. {
  17.     for(int i = n + 1; true; ++i)
  18.         if(czy_pierwsza(i))
  19.             return i;
  20. }
  21.  
  22. void wypelnij_tablice(int* tablica)
  23. {
  24.     tablica[0] = 2;
  25.     for(int i = 1; i < N; ++i)
  26.         tablica[i] = nastepna_pierwsza(tablica[i - 1]);
  27. }
  28.  
  29. void wypisz_tablice(int* tablica)
  30. {
  31.     for(int i = 0; i < N; ++i)
  32.         cout << tablica[i] << '\t';
  33.     cout << endl;
  34. }
  35.  
  36. int main()
  37. {
  38.     int tablica[N];
  39.     wypelnij_tablice(tablica);
  40.     wypisz_tablice(tablica);
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement