Advertisement
MeehoweCK

Untitled

Jul 9th, 2021
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool czy_pierwsza(int liczba)
  6. {
  7.     if(liczba < 2)
  8.         return false;
  9.     for(int i = 2; i * i <= liczba; ++i)
  10.         if(liczba % i == 0)
  11.             return false;
  12.     return true;
  13. }
  14.  
  15. int main()
  16. {
  17.     cout << "Podaj liczbe naturalna: ";
  18.     int n;
  19.     cin >> n;
  20.     if(czy_pierwsza(n))
  21.         cout << n << " jest liczba pierwsza.\n";
  22.     else
  23.         cout << n << " nie jest liczba pierwsza.\n";
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement