Advertisement
Guest User

Gg

a guest
Mar 26th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | Food | 0 0
  1. #include <cmath>
  2. using namespace std;
  3.  
  4. bool czyPierwsza(int n) {
  5. if (n <= 1) {
  6. return false;
  7. }
  8.  
  9. for (int i = 2; i * i <= n; ++i) {
  10. if (n % i == 0) {
  11. return false;
  12. }
  13. }
  14.  
  15. return true;
  16. }
  17.  
  18. int main() {
  19. int liczba;
  20. cout << "Podaj liczbe do sprawdzenia: ";
  21. cin >> liczba;
  22.  
  23. if (czyPierwsza(liczba)) {
  24. cout << "Liczba " << liczba << " jest liczba pierwsza.";
  25. } else {
  26. cout << "Liczba " << liczba << " nie jest liczba pierwsza.";
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement