Advertisement
JakubJaneczek

Zadanie 22

Apr 8th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int a,b;
  5.  
  6. int nastepna_pierwsza(int a)
  7. {
  8.     a=sqrt(pow(a,2))+1;
  9.     int b=2;
  10.     while (b<a)
  11.     {
  12.         if(a%b==0)
  13.         {
  14.             a++;
  15.         }
  16.         b++;
  17.     }
  18.     return a;
  19. }
  20.  
  21. int main()
  22. {
  23.     cout << "Podaj liczbe" << endl;
  24.     cin >> a;
  25.     cout << "Nastepna liczba pierwsza po" <<endl << a << endl;
  26.     cout<< nastepna_pierwsza(a)<<endl;
  27.     cout << "Nastepna liczba pierwsza po 6" << endl;
  28.     cout << nastepna_pierwsza(6) << endl;
  29.     cout << "Nastepna liczba pierwsza po 16" << endl;
  30.     cout << nastepna_pierwsza(16) << endl;
  31.     cout << "Nastepna liczba pierwsza po 36" << endl;
  32.     cout << nastepna_pierwsza(36) << endl;
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement