Advertisement
JakubJaneczek

Zadanie 21

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