Advertisement
Lukasz_Miskiewicz

Zadanie 21

Mar 31st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 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 main()
  19. {
  20. cout<<"Podaj liczbe naturalna"<<endl;
  21. cin >> a;
  22. if(liczba_pierwsza(a)==1)
  23. {cout << "Podana liczba jest pierwsza";}
  24. else
  25. {cout << "podana liczba nie jest pierwsza";}
  26.  
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement