LukaszPanko

Zadanie 21 + 22

Mar 29th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool LICZBA_PIERWSZA(int l)
  6. {
  7.     if(l<2)
  8.     {
  9.         return 0;
  10.     }
  11.     else if(l>2&&l%2==0)
  12.     {
  13.             return 0;
  14.     }
  15.     else if(l>3&&l%3==0)
  16.     {
  17.             return 0;
  18.     }
  19.     else if(l>5&&l%5==0)
  20.     {
  21.             return 0;
  22.     }
  23.     else
  24.     {
  25.             return 1;
  26.     }
  27. }
  28. int NASTEPNA_PIERWSZA(int l)
  29. {
  30.     l++;
  31.     for(int i=1;i<=10;i++&&l++){
  32.  
  33.         if(l<2||l==1)
  34.         {
  35.             cout<<2;
  36.             return 0;
  37.         }
  38.         else if(l==2)
  39.         {
  40.             cout<<3;
  41.             return 0;
  42.         }
  43.         else if(l>=3&&l<5)
  44.         {
  45.             cout<<5;
  46.             return 0;
  47.         }
  48.         else if(l%2!=0&&l%3!=0&&l%5!=0)
  49.         {
  50.             cout<<l;
  51.             return 0;
  52.         }
  53.     }
  54. }
  55.  
  56.  
  57.  
  58. int main()
  59. {
  60.     int liczba;
  61.     cout << "Podaj liczbe: ";
  62.     cin>>liczba;
  63.     std::cout<<LICZBA_PIERWSZA(liczba)<<endl;
  64.     if(LICZBA_PIERWSZA(liczba)){
  65.         cout<<"Liczba "<<liczba<<" jest liczba pierwsza"<<endl;
  66.     }
  67.     else{
  68.         cout<<"Liczba "<<liczba<<" nie jest pierwsza"<<endl;
  69.     }
  70.     cout<<"Nastepna liczba pierwsza wynosi: ";
  71.     NASTEPNA_PIERWSZA(liczba);
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment