Advertisement
MeehoweCK

Untitled

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