Advertisement
WiktorMalisak

Zadanie 22

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