Advertisement
MeehoweCK

Untitled

Jul 2nd, 2021
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 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 liczba;
  19.     cin >> liczba;
  20.  
  21.     if(czy_pierwsza(liczba))
  22.         cout << liczba << " jest liczba pierwsza.\n";
  23.     else
  24.         cout << liczba << " nie jest liczba pierwsza.\n";
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement