Advertisement
WiktorMalisak

Zadanie 27

Mar 31st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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, b;
  38.     cout << "Podaj pierwsza liczbe: ";
  39.     cin >> a;
  40.      cout << "Podaj druga liczbe: ";
  41.     cin >> b;
  42.     cout << "Liczby pierwsze z przedzialu od " << a << " do " << b << ":" << endl;
  43.  
  44.     for(int i=a; i<=b; i++)
  45.     {
  46.         if(LICZBA_PIERWSZA(i)==1)
  47.         {
  48.           cout << i << endl;
  49.         }
  50.     }
  51.  
  52.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement