Advertisement
Lukasz_Miskiewicz

Zadanie 22

Mar 31st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>//poniewa¿ "sqrt"
  3. using namespace std;
  4. int a,b;
  5.  
  6. int liczba_pierwsza(int a)
  7. { int b=2;
  8. int c=1;
  9. a=sqrt(pow(a,2));//math.h
  10. while (b<a)
  11. {
  12. if(a%b==0)
  13. {c=0;}
  14. b++;
  15. }
  16. return c;}
  17.  
  18. int nastepna_pierwsza(int a)
  19. {
  20. a=sqrt(pow(a,2))+1;
  21. int b=2;
  22. while (b<a)
  23. {
  24. if(a%b==0)
  25. {a++;}
  26. b++;
  27. }
  28. return a;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. cout<<"Podaj liczbe naturalna"<<endl;
  35. cin >> a;
  36. if(liczba_pierwsza(a)==1)
  37. {cout << "Podana liczba jest pierwsza";}
  38. else
  39. {cout << "podana liczba nie jest pierwsza "<<endl;}
  40. cout<<"następna liczba pierwsza po "<<endl;
  41. cout<<a<<" to "<<nastepna_pierwsza(a);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement