Advertisement
Michal_Pilarski

zad22

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