Advertisement
KingaGolas

zad21

Mar 30th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int liczba_pierwsza (int n)
  6. {
  7. for (int i=2; i>0; i++)
  8. {
  9. if (i==n)
  10. {
  11. return 1;
  12. }
  13. else if (n%i==0)
  14. {
  15. return 0;
  16.  
  17. }
  18. else if (n%i==0)
  19. {
  20. return 0;
  21. }
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. liczba_pierwsza(0);
  28. if(liczba_pierwsza(0)==1)
  29. {
  30. cout << "Podana liczba jest liczba pierwsza"<<endl;
  31. }
  32. else
  33. {
  34. cout << "Podana liczba nie jest liczba pierwsza"<<endl;
  35. }
  36. liczba_pierwsza(26);
  37. if(liczba_pierwsza(26)==1)
  38. {
  39. cout << "Podana liczba jest liczba pierwsza"<<endl;
  40. }
  41. else
  42. {
  43. cout << "Podana liczba nie jest liczba pierwsza"<<endl;
  44. }
  45. liczba_pierwsza(13);
  46. if(liczba_pierwsza(13)==1)
  47. {
  48. cout << "Podana liczba jest liczba pierwsza"<<endl;
  49. }
  50. else
  51. {
  52. cout << "Podana liczba nie jest liczba pierwsza"<<endl;
  53. }
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement