Advertisement
JakubJaneczek

Zadanie 27

Apr 8th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void przedzial_lpierwsze(int x1,int x2)
  6. {
  7.     cout<<"Liczby pierwsze:";
  8.     int s=0;
  9.     for(int i=x1;i<=x2;i++)
  10.     {
  11.         int a=0;
  12.         for(int d=i-1;d>=2;d=d-1)
  13.         {
  14.             if(i%d==0)
  15.             {
  16.                 a=a+1;
  17.             }
  18.             else{}
  19.         }
  20.         if(a==0)
  21.         {
  22.             s=s+1;
  23.             cout<<" "<<i;
  24.         }
  25.         else{}
  26.     }
  27.     if(s==0)
  28.     {
  29.         cout<<"Brak liczb pierwszych";
  30.     }
  31.  
  32. }
  33.  
  34. int main()
  35. {
  36.     int a,b;
  37.     cout<<"Poczatek: "<<endl;
  38.     cin>>a;
  39.     cout<<"Koniec: "<<endl;
  40.     cin>>b;
  41.     przedzial_lpierwsze(a,b);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement