PiotrJurek

Zad22

Mar 29th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool LICZBA_PIERWSZA(int n)
  6. {
  7. if(n>1)
  8. {
  9. for(int i=2; i<n; i++)
  10. {
  11. if(n%i==0)
  12. {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }
  18. else
  19. {
  20. return false;
  21. }
  22. }
  23.  
  24. int NASTEPNA_PIERWSZA(int n)
  25. {
  26. for(int i=n+1; true; i++)
  27. {
  28. if(LICZBA_PIERWSZA(i)==true)
  29. {
  30. return i;
  31. }
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. cout << NASTEPNA_PIERWSZA(13) << endl;
  38. cout << NASTEPNA_PIERWSZA(1) << endl;
  39. cout << NASTEPNA_PIERWSZA(80) << endl;
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment