Advertisement
Michal_Pilarski

zad21

Mar 22nd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n, a=0;
  5. int liczba_pierwsza(int n)
  6. {
  7.     if(n>1)
  8.     {
  9.         for(int i=2; i<=n; i++)
  10.         {
  11.             if(n%i==0)
  12.             {
  13.                 a++;
  14.             }
  15.         }
  16.             if(a==1)
  17.             {
  18.                 return 1;
  19.             }
  20.             else if(a>1)
  21.             {
  22.                 return 0;
  23.             }
  24.     }
  25.     else
  26.     {
  27.         return 0;
  28.     }
  29. }
  30. int main()
  31. {
  32.     cout << "Podaj liczbe naturalna: ";
  33.     cin >> n;
  34.     if(n<0)
  35.     {
  36.         cout<<"To nie jest liczba naturalna";
  37.         return 0;
  38.     }
  39.     if(liczba_pierwsza(n)==1)
  40.     {
  41.         cout<<"Jest to liczba pierwsza";
  42.     }
  43.     else if(liczba_pierwsza(n)==0)
  44.     {
  45.         cout<<"To nie jest to liczba pierwsza";
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement