RafalSobala

zad 21

Mar 31st, 2020
149
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. int a;
  6.  
  7. bool LICZBA_PIERWSZA(int a){
  8.  
  9. if(a<2){
  10.     return false;
  11. }
  12. for (int i=2;i*i<a;i++){
  13.     if(a%i==0){
  14.         return false;
  15.     }
  16.     return true;
  17. }
  18.  
  19. }
  20.  
  21.  
  22.  
  23. int main()
  24. {
  25.     cout << "Podaj liczbe: " << endl;
  26.     cin >> a;
  27.  
  28.     if(LICZBA_PIERWSZA(a)==1){
  29.         cout << "liczba jest liczbą pierwszą";
  30.     }
  31.     else{
  32.         cout<<"liczba nie jest liczbą pierwszą";
  33.     }
  34.  
  35.  
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment