Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. bool czy_pierwsza(int N)
  11. {
  12. if(N<2){
  13. return false; //gdy liczba jest mniejsza ni¿ 2 to nie jest pierwsz¹, zwracamy false i wychodzimy
  14. }
  15. for(int i=2;i<N;i++) {
  16. if(N%i==0) {
  17. return false; //gdy znajdziemy dzielnik, to dana liczba nie jest pierwsza, zwracamy false i wychodzimy z funkcji
  18. }
  19. }
  20.  
  21. return true;
  22. }
  23. int main()
  24.  
  25. {
  26.  
  27. int N;
  28.  
  29.  
  30.  
  31. cout << "ile liczb pierwszych ci podac:" ;
  32. cin >> N ;
  33. int i=0;
  34. int x=2;
  35.  
  36. while(i<N){
  37.  
  38. if (czy_pierwsza(x)==true){
  39. cout << x << " ";
  40. i++;
  41. }
  42. x++;
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement